Understanding WordPress Excerpts

A number of WordPress users find themselves over on the WordPress Forum looking for a code solutions to show excerpts and not full posts on the home page of their website, there are many different theme, and some have options to choose the post output.

In this post we will look at several solutions and how to get the best out of using excerpts, we will show a code solution for the twenty eleven theme, however on this website we do not use a code solution, we only use the built in WordPress editor.

The Excerpt

The excerpt can be a number of words or characters from the post, or a custom excerpt crafted for the posts content, first we need to understand what, when, where and why we would want to use an excerpt.

What we want to achieve is to sell the content of the post in as few words as possible, with a teaser, the first sentences or summary text.

When to show the excerpt and not the full post would be on list pages and archives, when the visitor is browsing the website or searching the posts.

Where to show the excerpts would be on the search and home pages to get as much information on the page without the website visitor not having to scroll down through other posts to find what they are looking for.

Why we use excerpts is when we have large post content and lots of posts, if our website is page based and we have only a few posts then excerpts might not be required, if we have lots of long posts then they are really a good thing.

The Myth

The number of posts on the WordPress forum for WordPress users that are wanting to show posts not excerpts grows each week, and most are looking for a code solution, it is a myth that there is a need to change code to show excerpts on a WordPress website, when there is a perfectly good solution already built into the post Editor.

The Editor More Tag

If we look at the twenty eleven theme’s home page we will see that the full post content is displayed, there is no option in the themes setup to change this.

excerpt-1

Let us look at the editor’s more tag, this will give us a lot of control as to how much of the post we want to display, before the read more link is displayed, we insert the more tag by adding a carriage return and just clicking the more icon or using the shortcut keys.

excerpt-2

What has just happened let us have a look at the HTML tag that has been inserted by the editor.

excerpt-2-2

If we view our home page now we have a nice tidy excerpt and read more link to the full post, in 99% of cases this will do for most website users, as they can construct the post and control the excerpt length and where the read more will show.

excerpt-3

But What If?

But what if the first couple of sentences do not give enough information, or the returned excerpt has text that needs images within the post to be show?

Then we do need to get “under the hood” and tinker with a little code, lets use the twenty eleven theme and change the code, we start with a child theme, you can grab one from here, and we open the folder and add (copy not cut) the content.php file from the twenty eleven theme’s folder.

excerpt-4

Opening the content.php file we look for line 35 and the if is search condition.

excerpt-5

Now we need to add a condition to include the or home page ‘is_home()’ in our excerpts section.

excerpt-6

If upload activate and view the child theme we can see the excerpt, not a good look cut off half way through a sentence.

excerpt-7

Custom Excerpts

We do not need to change code unless we want to use a custom excerpt, we would use these where the normal excerpt does not explain what our post is really about, or we want to show a block of text that is further down the post.

We go to screen options and turn on the excerpt text box, and we can now add our own text for any posts where the standard excerpt will just not do.

excerpt-8

Now we have full control over excerpts on our website, and we hope this will help visitors understand more about showing WordPress post excerpts.

excerpt-9

Notices

We do require your feedback to improve our themes and tutorials, please leave your comments good or bad.

Code disclaimer information

If this document contains programming examples, www.DigitalRaindrops.net grants you a nonexclusive copyright license to use all programming code from which you can generate similar functions tailored to your own specific needs.

All sample code is provided by http://DigitalRaindrops.net for learning illustrative purposes only.

These examples have not been thoroughly tested under all conditions. www.DigitalRaindrops.net, therefore, cannot guarantee or imply reliability, serviceability, or function of these examples.

All programs contained herein are provided to you “AS IS” without any warranties of any kind. The implied warranties of non-infringement, merchantability and fitness for a particular purpose are expressly disclaimed.

Membership

Registration and Membership is no longer required for downloading files or interacting with Digital Raindrops, posting a comment or topic in the forum does use Captcha to reduce spammers.

This website is a tool to support and promote WordPress and Artisteer theme development, please support, share and give credit for any benefits you gain from the tutorials on this website.

2 thoughts on “Understanding WordPress Excerpts

  1. Hi,

    On my post I use a ‘more tag’ under a photo and fill the ‘Excerpt’ with summarized info from that post which I want to be displayed on my ‘home page/index’ posting. The ‘more tag’ is working as one picture is displaying out of the four but the summarized excerpt is not displayed. It does have the ‘Continue Reading’.
    Is there code I need to add for this to work?

    Regards,
    T

  2. I forgot to mention, when updating the content.php with ‘is_home() ||’
    the custom ‘Excerpt’ display, but does not display the photo before the ‘more tag’.

Leave a Reply

Connections

Connect with Us
Follow Digital Raindrops on Twitter Join Digital Raindrops on Facebook
Share

Related Posts

Posted in Blog

Read More

Posted in Tips

colorizer-1_thumb.png

We thought we would use the WordPress Twenty Eleven theme and the the Farbtastic color picker to colorize our theme from the website front page instead of the admin area. We have been looking at the $_SESSION variable, so we thought … Continue reading

Read More

Posted in Twenty Eleven

pluggable-image2_thumb.png

In April 2011 we wrote a post on pluggable functions, since then we have been looking at other functions like post classes, which we used in the first release of our photo blogging theme. While loitering over on the WordPress … Continue reading

Read More