Skip to content

Everything for WordPress, web development — and beyond

✂️ How to change excerpt length in WordPress

✂️ How to change excerpt length in WordPress

You visit a blog archive and see "bricks": one post has a half-screen announcement, another has just two dry lines. This happens because WordPress by default trims excerpts to 55 words, a number invented nearly two decades ago and left untouched ever since.

The problem is that a universal length is never right. A news site needs 20 words, a longread needs 80, and a portfolio needs just 10. The good news: you can set your own length without plugins, using a single filter in functions.php. And without risking your site.

💡 Quick overview:

  • Understand what an excerpt is and why 55 words is not a rule
  • Change the length via the excerpt_length filter (2 lines of code)
  • Set different lengths for the homepage, categories, and custom post types
  • Choose a plugin if code is not an option, and learn what works in 2026
  • Find answers: excerpt vs "Read more," duplicate content, custom announcements

What is an excerpt and why its length matters

An excerpt is an automatic post summary that WordPress generates from the first 55 words of text. It appears in blog feeds, on category pages, in on-site search results, and in RSS feeds. If the author has not filled in the "Excerpt" field manually, the automatic system kicks in.

The number 55 came from early versions of the CMS and has not changed since version 2.7. Back then, the average post was 300-400 words, and 55 was a reasonable compromise. Today, a typical article on techblog runs 1500+ words, and a short excerpt loses meaning: readers do not understand what the post is about, and search engines see broken text in snippets.

Beyond aesthetics, there is a technical aspect. If an excerpt cuts off mid-sentence, Google may use that fragment in meta description, and your snippet in search results looks sloppy. A clean, meaningful excerpt of a defined length fixes the situation.

Changing the length via the excerpt_length filter

The most reliable method is using the built-in excerpt_length filter. It has existed in the WordPress core since version 2.7.0 and does not depend on themes or plugins. It works everywhere the the_excerpt() function is called.

Here is the minimal code for your child theme's functions.php file:

1/**
2 * Changes excerpt length to 30 words.
3 *
4 * @param int $length Current excerpt length.
5 * @return int New excerpt length.
6 */
7function mytheme_excerpt_length( $length ) {
8 return 30;
9}
10add_filter( 'excerpt_length', 'mytheme_excerpt_length', 999 );

What matters here:

  • Priority 999 is the key detail. WordPress internally applies its own filter with the default priority (10). If you do not specify a high priority, your callback runs before the system one and gets overwritten with 55. 999 guarantees your filter executes last.
  • Return an integer, only integer. A string '30' will trigger a PHP Warning in strict mode.
  • Child theme: do not edit the parent theme's functions.php, changes will be lost on update. If you do not have a child theme, create one or use the Code Snippets plugin.

The code above changes the length for all the_excerpt() calls on the site. The number 30 is an example; substitute your own. For a news site, 20-30 words is typical; for an analytical blog, 50-70; for a portfolio, 10-15.

If your site runs over HTTPS and uses a modern PHP version (8.0+), you can write it even shorter with an arrow function:

1add_filter( 'excerpt_length', fn( $length ) => 40, 999 );

But for compatibility with older projects, stick with the first variant using a named function.

Different lengths for different pages

A universal number is convenient but rarely optimal. On the blog homepage you need to hook readers with an extended summary (60-70 words), while in a "Related Posts" widget you need a brief line of 15-20 words. WordPress lets you set conditional logic through standard context-checking functions:

1function mytheme_conditional_excerpt_length( $length ) {
2 if ( is_front_page() && is_home() ) {
3 return 70; // Blog home page
4 }
5 if ( is_category() || is_tag() ) {
6 return 45; // Category and tag pages
7 }
8 if ( is_search() ) {
9 return 30; // Search page
10 }
11 if ( is_page_template( 'template-portfolio.php' ) ) {
12 return 15; // Portfolio template
13 }
14 return 55; // Everything else
15}
16add_filter( 'excerpt_length', 'mytheme_conditional_excerpt_length', 999 );

This approach covers the vast majority of real scenarios. The same logic applies to custom post types via is_singular( 'product' ) or is_post_type_archive( 'portfolio' ).

An important nuance: not every theme honestly uses the_excerpt(). Some premium themes (especially older ones with their own page builders) call wp_trim_words() directly or use custom wrappers. The excerpt_length filter will not work in such cases. If nothing changed after adding the code, open the theme's functions.php and look for alternative calls; the problem is usually solved by replacing the custom function with the standard the_excerpt().

Plugins: are they worth it?

The market for excerpt management plugins is small; most tasks are solved by the code from the previous sections. The historically popular Advanced Excerpt (100,000+ active installs in the past) has not been updated or tested with the latest WordPress versions since 2024. On WP 6.8+ the plugin does not work, and user reviews confirm this. Installing it in 2026 makes no sense.

What is actually available:

  • Code Snippets is a free plugin that lets you add PHP code in the admin panel without editing functions.php. Works for any snippet from this article: paste the excerpt_length filter, activate, done. Advantage: does not fear theme updates. Download: Code Snippets on WordPress.org.
  • WPCode is a newer tool with a visual interface for inserting snippets, conditional logic, and a cloud library of ready-made recipes. If you manage multiple sites and do not want to duplicate code, WPCode is more convenient.

Both plugins do not specialize in excerpts specifically; they solve a broader task. But for our purpose this is enough: you add the filter once and forget about it.

Code Snippets plugin in the WordPress admin panel

If you firmly want a GUI interface specifically for excerpts (length input fields, checkboxes, HTML tag selection), as of 2026 there is no separate actively maintained plugin with such functionality in the WordPress.org repository. All that previously existed are either abandoned or conflict with PHP 8.2+. In this situation, learning the excerpt_length filter is more reliable: two lines of code that will not break with any CMS update.

Before moving to common questions, here is a short video showing the process of adding code to a WordPress theme:

⁉️🤔 Common questions

What is the difference between excerpt and the "Read more" tag?

The <!--more--> tag ("Read more" button) cuts off the post where you place it and preserves all formatting: images, lists, headings. An excerpt is always plain text without HTML tags (unless a plugin is used). "Read more" controls display on the post page itself; excerpt controls display on archive pages. These are two different mechanisms that can work simultaneously.

Does excerpt create duplicate content for SEO?

No. If excerpt is generated by the the_excerpt() function on archive pages, search engines see it as meta description for those pages, not as duplicate content. Moreover, a properly configured excerpt helps Google form a relevant snippet. Duplicate issues arise only if you insert the full post text on both the archive and single pages without a canonical URL.

How do I set a fully custom announcement text?

In the WordPress post editor there is an "Excerpt" field. If it is filled, the system uses your text instead of the automatic one. In the classic editor, enable the field via "Screen Options" at the top right. In the block editor (Gutenberg), use the sidebar "Post" → "Excerpt" tab. A custom excerpt takes priority over any excerpt_length filter.

Can I preserve HTML in automatic excerpts?

The standard excerpt_length filter does not manage tags; wp_trim_excerpt() always strips HTML. To preserve formatting, you need a separate approach: either a plugin (but none work in 2026), or replacing the standard excerpt generator via the wp_trim_excerpt filter with your own code. This is an advanced technique for developers.

Why does the filter not work with my theme?

Three typical reasons: 1) the theme does not call the_excerpt() but uses a custom function (check archive.php, category.php, search.php templates); 2) the filter priority is lower than WordPress's built-in handler (use 999); 3) the functions.php file was edited in the parent theme rather than the child theme, and changes were not picked up.

Changing excerpt length: code or plugin?

The excerpt_length filter covers the needs of the vast majority of WordPress sites. Two lines in functions.php, and excerpt length becomes exactly what you want: on the homepage, in categories, in search, for custom post types. There is no need to look for separate excerpt plugins in 2026; they are either abandoned or redundant.

If you have never edited functions.php, start with Code Snippets. It is free, safe, and does not depend on theme updates. Once you get comfortable, conditional logic with is_front_page() and is_category() will unlock a level of control that no GUI excerpt plugin has ever provided.