WordPress / Web Development Tutorials
(Best WordPress Tutorials)

CSSHTMLJavaScriptjQueryMySQLPHPSilvaTechnologiesWooCommerceWordpress
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, website design and basically anything digital-related. His main expertise is with WordPress and various other CMS frameworks. If you need responsive design, SEO, speed optimisation or anything else in the world of digital, you can contact Silva Web Designs here; [email protected]

It’s good to share

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

Join the discussion

Related Posts

Related - How to Load More Posts using Ajax with a Button or on Scroll in WordPress

Wordpress / 17th February 2022

How to Load More Posts using Ajax with a Button or on Scroll in WordPress

Read More Related - 7 Tips to Stand Out as a Freelance Web Developer

Technologies / 12th January 2022

7 Tips to Stand Out as a Freelance Web Developer

Read More