Categories
WordPress

How to show only excerpts in blog (post list) page?

There are two ways I got this done (any of these will work):
1. content.php is the file that controls this aspect
2. You can edit the theme OR the child theme functions.php file:

There are two ways I got this done (any of these will work):

1.
content.php is the file that controls this aspect, you should look to that file to change the_content to the_excerpt (for the right conditional tags).

PS: If this affect the main post/page display, then you need a condition to be added, such as:

if ( is_singular() ) {
        the_content();
   } else { the_excerpt(); }

As you’ll have to change the theme’s code, make sure you’re working in a child theme.

2.
You can edit the theme OR the child theme functions.php file:

/* Replace the content with excerpts on home page */
add_filter( 'the_content', 'replace_content_with_excerpt', 100 );
//http://wordpress.stackexchange.com/a/77947/25187

/**
 * Return excerpt if we are not on a singular post view.
 *
 * @param  string $content
 * @return string
 */
function replace_content_with_excerpt( $content ) {
   if ( is_singular() ) {
        return $content;
   }

   // remove our filter temporarily.
   // Otherwise we run into a infinite loop in wp_trim_excerpt().
   remove_filter( 'the_content', __FUNCTION__, 100 );
   $excerpt = apply_filters( 'the_excerpt', get_the_excerpt() );
   add_filter( 'the_content', __FUNCTION__, 100 );
   return $excerpt;
}

Ref: https://wordpress.org/support/topic/how-do-i-show-only-excerpts-in-twenty-seventeen-theme/#post-9965481

QR Code

By Green

AMP, Branding, Copywriting, Marketing, Multilingual, WordPress - https://linktr.ee/gjazz

Leave a Reply

Your email address will not be published. Required fields are marked *