Helping you build a better website
(and other interesting web stuff)

CSSHTMLJavaScriptjQueryMSSQLMySQLPHPSilvaTechnologiesWordpress
Silva Web Designs - Blog

How to show excerpts of posts on homepage in WordPress

I was trying to show the excerpt for our homeage and we found that a lot of people are saying that by changing:-


<?php the_content(); ?>

to


<?php the_excerpt(); ?>

In your content.php file should do the trick. It may work for some people but in our case, it showed the excerpt on the homepage as we wanted, but then when you clicked on the actual post, it displayed just the excerpt without having an option to read the full post. Now there are many ways that you can fix this, here are two different methods:

1.) On our website, we wanted the homepage to show the_excerpt then when clicking on the post we wanted it to display the full post, to do this, edit the content.php and change the following:


the_content( __('Read more...', 'silva') );

to


if(is_home() || is_front_page()) {
    the_excerpt( __('Read more...', 'silva') ); 
}
else {
    the_content( __('Read more...', 'silva') ); 
}

Simply modify the code to suit your WordPress site, as ‘zilla’ is specific to our theme.

Alternatively, you can just change the_content to the_excerpt and then put < !--more-- > (without spaces) at the end of the post which will show a ‘read more’ option at the bottom of the post. We personally preferred the first option but it all goes down to personal preference.

 

Nathan da Silva - Profile

Posted by: Nathan da Silva

Nathan is the Founder of Silva Web Designs. He is passionate about web development and web site design. His expertise is WordPress & Magento as well as many other frameworks. Would you like to work with Nathan? Send him an email on [email protected]

It’s good to share

One thought on “How to show excerpts of posts on homepage in WordPress

Join the discussion