• Skip to primary navigation
  • Skip to main content
  • Skip to footer
  • Books
    • Content Strategy for WordPress (2015)
    • WordPress for Web Developers (2013)
    • Beginning WordPress 3 (2010)
  • Blog
    • Content Modeling for WordPress
    • WordPress Hidden Gems
    • Web Design
  • Work
    • MLIS Class Projects (2019-2022)
    • Portfolio (2002-2019)
    • Services
    • WordPress Plugins
    • WordPress Themes
    • Presentations and Interviews
    • on GitHub →

Stephanie Leary

Writer, WordPress consultant, recent MLIS grad

  • About
    • Press Kit
    • Presentations and Interviews
  • Contact Me

Take control of your excerpts

February 9, 2010 Stephanie Leary 4 Comments

Here are three short functions you can add to your theme’s functions.php file to change the way excerpts work on your site.

When you use the_excerpt() in a theme file, WordPress will first use the contents of the Excerpt field from your Post→Edit screen. If it’s empty, WordPress will auto-generate an excerpt. These first two functions change the way excerpts are generated. They will not affect any excerpts you write by hand.

Auto-generated excerpts are 55 words long. To change the length, return the number of words you prefer:

// Changing excerpt length
function change_excerpt_length($length) {
    return 100;
}
add_filter('excerpt_length', 'change_excerpt_length');

Auto-generated excerpts have ‘[…]’ appended to them. To remove or change this, use:

// Changing excerpt 'more' text (normally […])
    function change_excerpt_more($more) {
    return ' (Continue reading…)';
}
add_filter('excerpt_more', 'change_excerpt_more');

In a standard WordPress setup, only posts have excerpts. If you’d like to use them for pages too, you can install a plugin (PJW Page Excerpt, Excerpt Editor) or just add this to functions.php:

// add excerpts to pages
function add_page_excerpt_meta_box() {
    add_meta_box( 'postexcerpt', __('Excerpt'), 'post_excerpt_meta_box', 'page', 'normal', 'core' );
}
add_action( 'admin_menu', 'add_page_excerpt_meta_box' );

There is no easy function to prevent WordPress from stripping the HTML formatting from your excerpts. There are two plugins you can use, however: the_excerpt Reloaded and Advanced Excerpt.

WordPress excerpts, Metadata, Posts and Pages

Reader Interactions

Comments

  1. Matt says

    February 18, 2010 at 3:09 am

    Is it also possible to show a “Continue Reading…” Link even when the_excerpt is modified in the backend? You know in WordPress 2.9 you have the option to set an excerpt text right underneath the normal post-text. If I do that, the “Continue Reading…” Link isn’t visible. Can I change that behaviour so that this Link is also there if the excerpt is customized by myself?

    Reply
  2. nasir says

    December 12, 2012 at 11:22 am

    But i need to remove continue reading only on home not permanently …….

    Reply
  3. Gordon Langley says

    October 6, 2015 at 4:01 pm

    Thanks Stephanie, I love 5 minute fixes! Thank you.

    I wanted to prompt users to write an excerpt and not to use auto excerpts, this works a treat:

    // Changing excerpt length
    function change_excerpt_length($length) {
    return 0;
    }
    add_filter('excerpt_length', 'change_excerpt_length');

    // Changing excerpt 'more' text (normally […])
    function change_excerpt_more($more) {
    return 'You forgot to write an excerpt, buddy...';
    }
    add_filter('excerpt_more', 'change_excerpt_more');

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Footer

My Books

I’m a front end developer at Equinox OLI, working on open source library software. I was previously a freelance WordPress developer in higher education. You can get in touch here or on LinkedIn.

Copyright © 2023 Stephanie Leary · Contact