How to Set Post Excerpt Length in WordPress

1.6666666666667 from 5
from 6 user
(Rate this post)
How to Set Post Excerpt Length in WordPress

WordPress excerpt_length filter is responsible for modifying the default length for post excerpts. WordPress lets developers set their desired length for printing excerpts on themes. We want to try it in a working example to show you how the excerpt_length filter works in WordPress and how you can use this filter in your themes.

Smart developers always use WordPress filters and actions if they want to modify any core functionality and data.

WordPress introduced the excerpt_length filter to use when you want to modify the except length of posts.

The default excerpt length is 55 words in WordPress.

To change this number in a working example, you need to modify functions.php file of your current theme or create a simple WordPress plugin.

If you are editing the functions.php file of your theme, use these codes at the end of the file.

How to use excerpt_length filter in WordPress

Like using other WordPress filters. you can use excerpt_length filter easily:

add_filter('excerpt_length', function($length) {
	return 20; //sets length to 20!
}, 1000);

Copy and paste this code to your active theme functions.php or your custom plugin file.

These codes will change WordPress default excerpt length from 40 to 20. You can use any number instead.

What do you think about "How to Set Post Excerpt Length in WordPress"?

Your rating submit was successfull.

Your rating submit was not successfull.