How to change length of post excerpt in wordpress theme

How to change length of post excerpt in wordpress theme

To change the length of the post excerpt in a WordPress theme, you can modify the theme’s functions.php file. First, access the functions.php file by navigating to Appearance > Theme Editor in your WordPress dashboard. Then, add the following code to the file:

function custom_excerpt_length($length) {
return 30; // Change 30 to the desired number of words
}
add_filter('excerpt_length', 'custom_excerpt_length');

This code will adjust the default excerpt length. The 30 can be changed to any number, depending on how many words you want your excerpt to display. Once you save the changes, the new excerpt length will be applied across your site. Make sure to back up your functions.php file before editing to prevent any issues. Alternatively, some themes allow you to modify excerpt length directly through the theme customizer or settings panel.