How to Change Excerpt Length in WordPress

WordPress is a powerful content management system that allows users to easily create and manage their websites. One of the key features of WordPress is the ability to display excerpts of blog posts on the homepage or archive pages. By default, WordPress displays a limited number of words in the excerpts. However, you may want to change the length of the excerpts to better suit your website’s design or to provide more information to your readers.

In this article, we will guide you on how to change the excerpt length in WordPress.

Important: Before modifying your theme files, it’s strongly recommended to create a child theme. This preserves your customizations whenever your main theme receives updates. Avoid editing the parent theme directly, as changes will be overwritten upon updates.

Method 1: Using the Excerpt Length Filter

The first method involves using the excerpt length filter in your WordPress theme’s functions.php file. Here’s how you can do it:

  1. Access your WordPress dashboard and navigate to Appearance → Theme Editor.
  2. On the right-hand side, click on the “Theme Functions (functions.php)” file to open it.
  3. Scroll down to the bottom of the file and add the following code:
function wpnotch_custom_excerpt_length( $length ) {
    return 50; // Change the number to the desired length of words
}
add_filter( 'excerpt_length', 'wpnotch_custom_excerpt_length', 999 );

4. Save the changes by clicking on the “Update File” button.

Now, when you visit your website, you will see that the excerpts are limited to the number of words you specified in the code. You can modify the number in the return 50; line to adjust the length according to your preference.

Method 2: Using a Plugin

If you prefer a more user-friendly approach or do not have access to the functions.php file, you can use a plugin to change the excerpts length. Here’s how:

  1. Go to your WordPress dashboard and click on “Plugins” in the left-hand menu.
  1. Click on “Add New” and search for the “Advanced Excerpt” plugin.
  1. Click on the “Install Now” button and then activate the plugin.
  2. Once activated, go to “Settings” → “Excerpt” to configure the plugin.
  1. Adjust the “Excerpt Length” option to your desired number of words.
  2. Save the changes.

The plugin will automatically update the excerpts length on your website based on the settings you specified.

In addition to changing the length of the excerpts, you may also want to customize the “Read More” link that appears at the end of the excerpts. By default, WordPress displays “…” as the read more link. Here’s how you can change it:

  1. Access your WordPress dashboard and navigate to Appearance → Theme Editor.
  2. On the right-hand side, click on the “Theme Functions (functions.php)” file to open it.
  3. Scroll down to the bottom of the file and add the following code:
function wpnotch_custom_excerpt_more( $more ) {
    return ' <a class="read-more" href="'. get_permalink( get_the_ID() ) . '">Read More</a>';
}
add_filter( 'excerpt_more', 'wpnotch_custom_excerpt_more' );

4. Save the changes by clicking on the “Update File” button.

Now, when you visit your website, you will see that the “Read More” link appears with the text “Read More” instead of “[…]” at the end of the excerpts. You can modify the “Read More” text by replacing it with any text within the last function we just added to customize the link text according to your preference.

Changing the excerpts length in WordPress allows you to have more control over how your content is displayed on your website. Whether you choose to use the excerpt length filter, a plugin, or customize the read more link, these methods provide you with the flexibility to create a website that meets your specific needs.

Remember, it’s important to consider the readability and user experience when adjusting the excerpts length. Striking the right balance between providing enough information and enticing readers to click through to the full post is key.

We hope this guide has helped you understand how to change the excerpts length in WordPress. Feel free to explore these methods and find the one that works best for you and your website.

Discover more from WP Notch

Level up your skills. Get expert tips delivered straight to you. Subscribe!

Continue Reading