• Skip to main content
  • Skip to primary sidebar
  • Skip to footer

WP Thinker

The WordPress Playground

  • Snippets
  • Best
  • Guides
  • Reviews
Home / Code Snippets

February 28, 2021 Jayan

Change WordPress Post Excerpt Length

WordPress post excerpts are a great way to quickly present the content to the readers without having them check the entire article to know what it is about. By default, WordPress sets the Excerpt length to 55 words. In most cases, it will be enough and suitable for almost any kind of website. But for some, it can be a bit too long or a bit too short. So, if you want to make changes to the default excerpt length WordPress shows by default, you can change it using the following code.

Usage

  • To limit or increase the length of the short content displayed on the website to provide a better user experience.
  • To avoid duplicate content issues on websites that publish smaller content and indexes archive pages.
  • For magazine websites with a lot of articles and want to keep the space consumed by posts to the minimum by only displaying the necessary information such as the post title, thumbnail, category, etc.

Code

// Change WordPress excerpt length to 25 words
function wpt_change_excerpt_length( $length ) {
  return 25; // change 25 to your choice
}
add_filter( 'excerpt_length', 'wpt_change_excerpt_length', 9999);

You can either increase the limit or decrease it. It is upto you. But do not increase it too much in case your content is very short (such as news websites).

Explanation

  1. Just the comment. You may remove it if you don’t need it.
  2. Declaring the wpt_change_excerpt_length function and passing the $length argument which will define our excerpt length.
  3. Returning a value to the $length attribute to pass to the excerpt_length hook. The words after the // is a comment which you can keep or remove if you do not want it.
  4. Just closing the function.
  5. Adding a filter to the excerpt_length function with our newly created function wpt_change_excerpt_length and setting the priority 9999 so that the filter will be applied late without interfering with other important executions.

Primary Sidebar

Related Articles

Footer

WPThinker-White-Logo

Website

  • About Us
  • Advertise
  • Write for Us
  • Contact Us

Policies

  • Privacy Policy
  • Terms and Conditions
  • Facebook
  • Twitter
  • Pinterest
Copyright © 2025 · WP Thinker
This website uses cookies to serve you better. By continuing to use this website, you agree to our cookie and Privacy Policy.