How to Change the Default WordPress Excerpt Length for Better Content Control

The WordPress excerpt is a short summary of a post that appears on archive pages, search results, and in some cases, on the home page of your site. By default, WordPress uses a maximum of 55 words for the excerpt length. However, sometimes you may want to change the default excerpt length to better fit your needs. In this tutorial, we’ll show you how to change the default WordPress excerpt length.

Step 1: Open the functions.php File

The first step is to open the functions.php file of your WordPress theme. You can access this file through your WordPress dashboard by going to Appearance > Theme Editor and selecting the functions.php file from the list of theme files.

Step 2: Add the Code Snippet

Once you have opened the functions.php file, you can add the following code snippet to change the default WordPress excerpt length:

function custom_excerpt_length( $length ) {
    return 20; // Change this number to the desired excerpt length
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );


In the code snippet above, we are defining a new function called custom_excerpt_length that takes a single argument $length. This argument represents the default WordPress excerpt length.

In the next line, we are using the return statement to set the desired excerpt length. In this example, we have set the excerpt length to 20 words. You can change this number to any value that you prefer.

Finally, we are using the add_filter function to apply the new excerpt length to the WordPress site. The 999 parameter ensures that this filter is applied after any other filters that may affect the excerpt length.

Step 3: Save the Changes

Once you have added the code snippet to your functions.php file, click on the Update File button to save the changes. You can now visit your WordPress site and verify that the new excerpt length is being used.

Congratulations, you’ve successfully learned how to customize your WordPress site by changing the default excerpt length! This is a quick and easy way to give yourself more control over your site’s content and how it’s displayed to your readers. With this simple code snippet, you can adjust your excerpts to your exact specifications, allowing you to highlight the most important aspects of your content and encourage readers to explore more of what you have to offer. Remember to always make a backup of your functions.php file before making any changes, and happy customizing!

Support 🐶

If you found this article helpful, got a question or spotted an error/typo... Do well to leave your feedback in the comment section or help spread it by sharing this article. If you're feeling generous (and I hope you do) you can definitely help me by getting me a cup of coffee ☕.


You may like these too!

Leave a Reply

Your email address will not be published. Required fields are marked *