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 the home page here on Web-Tricks and I 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 actually 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 Web-Tricks, I wanted the homepage to show the_excerpt then when clicking on the post I wanted it to display the full post, to do this, edit the content.php and change the following:-

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

to


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

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 at the end of the post which will show a ‘read more’ option at the bottom of the post. I personally proffered the first option but it all goes down to personal preference.

 

It’s good to share

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

Join the discussion