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 →
WP Masonry PRO WordPress Theme

WP Masonry PRO

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

$25.00
CoolWP PRO WordPress Theme

CoolWP PRO

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

$25.00
MaxWP PRO WordPress Theme

MaxWP PRO

If you like MaxWP free WordPress Theme, you will love the premium version. MaxWP PRO is feature-rich, easy to use,...

$25.00
GridMode PRO WordPress Theme

GridMode PRO

Are you using the GridMode free WordPress Theme and looking for more advanced features? GridMode PRO theme is developed for...

$25.00
Clean Grid PRO WordPress Theme

Clean Grid PRO

If you like Clean Grid free WordPress Theme, you will love the premium version. Clean Grid PRO is an elegant,...

$25.00
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
MagShow PRO WordPress Theme

MagShow PRO

MagShow PRO is the premium version of MagShow free WordPress Theme with more advanced features. MagShow PRO version has 160+...

$25.00
HotWP PRO WordPress Theme

HotWP PRO

If you like HotWP free WordPress Theme, you will love the HotWP premium version. HotWP PRO is easy to use,...

$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 55 WordPress themes.