Home » Change The Excerpt Limit In WordPress

Modify the default (55) maximum number of words in WordPress post excerpt. Set the length according to your needs using the add_filter filter hook.

Requirements:

  • WordPress
  • functions.php file

Step 1.

Open the active theme’s functions.php file and create a function that will return the desired number of words for the post excerpt. In this example, the default number of excerpt words which is 55 will be reduced to 25.

Also use the function add_filter to allow the update of the default excerpt limit. Therefore will return only 25 words on each post excerpt called.

function my_excerpt_length( $length ) {
    return 25;
}
add_filter( 'excerpt_length', 'my_excerpt_length', 999 );

Test.

Open a page the display’s a post excerpt, typically on the home page is where the post excerpt is being displayed.

Result.

Before

After

References:


Posted

in

by

Tags:

Leave a Reply

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