WordPress offers a number of ways to show an introduction to a post that then links to the full post. They are commonly used on the home page of a site, or in category archive pages when you don’t want to list the full post content. Because there are different ways of accomplishing this, it can be a bit confusing as to how each method works.
To understand how WordPress deals with these post introductions, you have to know the distinction between manual excerpts, auto-generated excerpts, and posts that utilize the
The More Tag
The more tag let’s you define the part of the content that forms an introduction to the full post. To use it, you can either type in
(while in HTML mode) or use the more button inside the post editor. You have to place this tag in the right position in your content (effectively splitting the content). Now the interesting part is how the display is done. The more tag is only respected if the page it’s being displayed isn’t a singular post, page or custom post page. This makes sense in so far that if you are on the actual page of your post, you would want to show the full post. That’s great.
But what if you are on a different singular page and you want to display the teaser of a different post with a link to the full post? If your theme is using
to display this content it will show a full post regardless. That’s something to keep in mind.
Another interesting thing about using the more tag and having it displayed with the_content() is that you can specify a ‘more link text’.
the_content( 'continue reading...' );
This function also gives you the option to hide the introduction of the post when it is displayed on the actual post page.
the_content( 'continue reading...', true ); // default is false
That way you can write a custom teaser that will only show on your home page, but the teaser text isn’t repeated on the full post page.
If you don’t hide the teaser, the read more link will send the reader straight through to the section after the introduction. In the actual markup of the actual post page, a span element is inserted that has an id that is used to target that section directly from the link. Some people do choose to remove this default behavior however.
So apart from
, another function exists for displaying a post excerpt, which is appropriately called
.You could use the above mentioned technique for creating a post excerpt for your home page, but the_excerpt() is another way to show a post introduction. It’s conceptually different compared to using the more tag. When the_excerpt() is used, it will look to see if a manual excerpt has been set and if there is none, it generates an excerpt automatically. The automatic excerpt generator will grab the first x amount of words from the post content and render that content with plain formatting (ignoring images, headings and stylings that were applied to the post text). That’s a big difference compared to using the_content() with a more tag defined in the post, which will respect the original markup of the post.
You can customize the appearance of the rendering of the_excerpt by adding your own ‘read more’ link or altering the amount of words it uses to generate the excerpt. But really, the usefulness of automatically generated excerpts pales in comparison to using the more tag or using manual excerpts.
A lot of WordPress users don’t even know it exists, but you can set manual excerpts from the post editing screen. It may appear hidden if your screen settings are set to hide the excerpt meta box. That is easily remedied though. While manual excerpts are (by default) only activated for normal posts, you can add support for excerpts to any other post type (such as pages) with a line of code.
Manual excerpts give you full control over the excerpt and so they give you a means to define what is shown when the theme is using the_excerpt() to display content. Manual excerpts are also sometimes used for supplying summaries, or for descriptions of the page that appear in the head section of the page (not visible to users, but used by search engines and apps). Those are entirely different functions compared to the aim of providing an enticing introduction for a post. Because the manual excerpt also runs through the_excerpt, the output format is pure text (no images, special styles etc).
Making Sense Of Excerpts
The three built-in ways of displaying excerpts each have their pros and cons. It’s easy to get a little confused when you are trying to make the excerpts on your site display as you want them to. Context matters, you really have to understand what you are trying to achieve with the excerpt so you can use the most appropriate method.
The more tag approach is best for showing a teaser, a few lines that make visitors click through to the full page. You then have the power to hide the teaser from the full page, making the teaser purely function as a means to invite people to read the page. The downside to the more tag is that it requires an author to remember to manually insert the tag. If you don’t supply a more tag, the full post may be rendered and you also have the limitation of not being able to show just the teaser on pages that have a dedicated permalink.
Automatic excerpts are a crude means to provide introductions, because they are pure text and consist of a fixed amount of words with no regard for sentences and special formatting. They also make for lousy summaries unless the first sentences of a post are formulated in a favorable way.
Manual excerpts give a user a lot of flexibility. You can utilize them as summaries of a post and they don’t have to repeat a post’s content verbatim. By default, the formatting is bare bones, just like the automatically generated excerpt is. The downside to these manual excerpts is that user’s often don’t understand the benefits and it is an extra thing to remember while writing a post.
If you are setting manual excerpts as well as using the more tag to create teasers, know that
will show the manual excerpt and
will show the teaser as specified by the more tag placement.
Your Own Excerpt Display Functions
Given the limitations of each of the discussed methods, you may find that you need something custom. I’ve previously written about how to make an rss feed show teasers set by the more tag placement here. You may want show an excerpt with certain formatting preserved from the original post. You might want to set a character limit for the excerpt for tighter control. You can even write a function that automatically inserts a more tag if none is specified to have auto-generated teasers.