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 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 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.
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.
What has just happened let us have a look at the HTML tag that has been inserted by the editor.
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.
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.
Opening the content.php file we look for line 35 and the if is search condition.
Now we need to add a condition to include the or home page ‘is_home()’ in our excerpts section.
If upload activate and view the child theme we can see the excerpt, not a good look cut off half way through a sentence.
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.
Now we have full control over excerpts on our website, and we hope this will help visitors understand more about showing WordPress post excerpts.
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.
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.