How to Add Custom Excerpt Length in WordPress

Adjusting the length of excerpts in WordPress can enhance the readability of your blog. Here’s a quick way to change the excerpt length using a code snippet.

Step 1: Access Your Theme’s Functions.php File

  1. Log in to Your WordPress Dashboard and navigate to "Appearance" > "Theme File Editor".
  2. Select the functions.php file clicking on "Theme Functions (functions.php)".

Step 2: Add the Code Snippet

Add the following code to set your desired excerpt length. For example, this sets the excerpt length to 20 words:

function themesdna_custom_excerpt_length( $length ) {
    return 20;
}
add_filter( 'excerpt_length', 'themesdna_custom_excerpt_length', 999 );

Step 3: Save and Test

  1. Click the "Update File" button to save the changes.
  2. Visit your site and check that the excerpt length has been adjusted.

You can manage how much content appears in your excerpts with this quick change, which will enhance the user experience on your site.

Our WordPress Themes

Below are some of our premium WordPress themes. View all our free and premium WordPress themes →
FlashWP PRO WordPress Theme

FlashWP PRO

If you like FlashWP free WordPress Theme, you will love the premium version. FlashWP PRO is advanced, more user friendly,...

$25.00
EliteWP PRO WordPress Theme

EliteWP PRO

If you like EliteWP free WordPress Theme, you will love the premium version. EliteWP PRO is an advanced, very user...

$25.00
MagPal PRO WordPress Theme

MagPal PRO

$25.00
GridWP PRO WordPress Theme

GridWP PRO

If you like GridWP free WordPress Theme, you will love the premium version. GridWP PRO is an improved version of...

$25.00
RapidWP PRO WordPress Theme

RapidWP PRO

Did you try RapidWP Free WordPress Theme?, Then you will love the premium version. RapidWP PRO is an improved, more...

$25.00
GridNext PRO WordPress Theme

GridNext PRO

If you have used GridNext Free WordPress Theme, then you will love the premium version. GridNext PRO version has color...

$25.00
PrimeWP PRO WordPress Theme

PrimeWP PRO

If you like PrimeWP Free WordPress Theme?, Then you will love the premium version. PrimeWP PRO is an more improved...

$25.00
FreshWP PRO WordPress Theme

FreshWP PRO

If you like FreshWP free WordPress Theme, you will love the premium version. FreshWP PRO is very user friendly, feature-rich,...

$25.00

Can't you choose a single theme? Purchase All Themes for $75.

Save money with our low, one-time price for access to all of our 56 WordPress themes.