Change the Default Excerpt Length in WordPress

The following filter lets you set the excerpt length that WordPress displays when calling the the_excerpt function. In this example we set the excerpt length to 20 words (the default is 55):

function sv_excerpt_length( $length ) {
	return 20;
}
add_filter( 'excerpt_length', 'sv_excerpt_length', 999 );

The filter only affects excerpts that WordPress generates automatically from the post content. A manual excerpt entered in the editor is shown in full. The priority of 999 makes sure your value wins over a theme or plugin that sets its own length.

This uses the excerpt_length filter. Learn more in WordPress Hooks Explained.

Discussion
[  0 Comments  ]

Leave a Comment

To add code, use the buttons below. For instance, click the PHP button to insert PHP code within the shortcode. If you notice any typos, please let us know!