How to change Wordpress excerpt size?


Longer excerpt to show up in WordPress feedRecently I had a little challenge with an rss-feed. The normal excerpt which is added to the feed contains 55 words in total (see the Business and Faith feed as an example). The problem was that I needed the excerpt to contain more words as some blog catalogues used the excerpt to share the blog posts, but they allowed more than 55 words. Thus the excerpt looked very bad, because after the 55 words from the article from our feed characters such as “[…] The post” started showing up.

This problem can for sure be solved in many different ways, but as I looked around I found one solution that I liked a lot and which was very easy to use. The following script should simply be added to your functions.php file in WordPress (Appearance / Editor) and there you can decide how many words should be included in the excerpt yourself. I set the amount to 80 in my blog, but you can of course decide for yourself how many words you want the WordPress excerpt to contain.

Add the following script to functions.php to change WordPress excerpt size
function custom_excerpt_length( $length ) {
return 80;
add_filter( ‘excerpt_length’, ‘custom_excerpt_length’, 999 );

If you use the Twenty Twelve theme in WordPress you need to add the following code:
function twentytwelve_excerpt_length( $length ) {
return 40;
add_filter( ‘excerpt_length’, ‘twentytwelve_excerpt_length’ );

Do not forget that if you update your theme this will be lost if you add it directly to your functions.php file. You should therefore consider using a WordPress Child theme which will keep this change even when updating your theme.

No responses yet

    Leave a Reply