Tweet about this on Twitter41Share on Facebook0Share on LinkedIn0Share on Google+0Buffer this page

By default, WordPress displays post excerpts of 55 words. However, this little snippet of code can easily change the default length of the excerpt on any WordPress post.

Most WordPress themes will use the built-in WordPress function called the_excerpt(); to create a 55 word summary of your WordPress post. This summary is simply the first 55 words of your WordPress post. On my site I decided that the 55 words were too much and I wanted to shorten that. It’s easy when using this quick little bit of code.

Customize WordPress

 

By default, <?php the_excerpt(); ?> will display a summary of the first 55 words of your WordPress post.

Are you ready to change the default WordPress excerpt length?

It’s always a great idea to backup any themes files you’re going to work on before editing it, as any error will give major WordPress theme errors.

I normally always copy the file contents into Notepad, and use it as a backup just in case things go wrong. But by the fact that you see this site working, you can be sure that the code works!

How to change the default excerpt length of WordPress posts

Easy. On your WordPress Dashboard, click on Appearance > Editor > Select your WordPress theme, edit the function.php file.

Edit your theme functions file function.php and add the following bit of code to the very bottom of the file.

function new_excerpt_length($length) {
return 30;
}
add_filter('excerpt_length', 'new_excerpt_length');

Remember to place it just above the last line of the code ?> or }, and make sure you DON’T add any new lines <ENTER KEY> or spaces (other than what’s in the code) as this will cause an error in your WordPress installation.

So where does WordPress change the number of words for the excerpt summary?

return 30;

Feel free to change “30” to be any number of words you want it to be. Just remember than without this custom code to change the default length of the WordPress excerpt, the excerpt will be 55 words.

So change the 30 to be whatever you want and you now have a new custom WordPress excerpt summary size. Enjoy changing the default excerpt length in WordPress, it’s easy and a great way to professionally customize your WordPress blog.