excerpt

All About Excerpt on WordPress

Last modified: January 13, 2020

Cloudways

Excerpt is a shortened version of the text on your posts. When you see a main blog page that shows you the last 10 posts on the blog or category, you would usually see:

  1. An image
  2. Title
  3. Short text
  4. Date posted

The short text is called excerpt and it’s the first ___ amount of words from a post.

Show More

* This button will show the rest of the post and open up an offer from a vendor

How to Change Excerpt Length?

Sometimes the default excerpt length isn’t good for you and you need to lengthen it or shorten it. Here is how you do that:

Paste this into your functions.php file:

function custom_excerpt_length( $length ) {
  return 35	;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );

 

Just change the number 35 into anything you want.

How to Change Excerpt Read More?

Have you seen themes that at the end of the excerpt you see this: […]? or a link saying read more?

Well, this is how to change that:

function wpdocs_excerpt_more( $more ) {
    return '...';
}
add_filter( 'excerpt_more', 'wpdocs_excerpt_more' );

 

This is the simple option, just add … at the end of the excerpt and you are done. But what if you want to add a link to the post?
Here you go:

function wpdocs_excerpt_more( $more ) {
    return sprintf( '<a class="read-more" href="%1$s">%2$s</a>',
        get_permalink( get_the_ID() ),
        __( 'Read More', 'textdomain' )
    );
}
add_filter( 'excerpt_more', 'wpdocs_excerpt_more' );

 

You can read more about excerpt here.

 

Recap:
Save 4 Later
Email liked links to yourself