WordPress.org

Forums

Increasing excerpt length (3 posts)

  1. mattstat
    Member
    Posted 5 years ago #

    I wanted to increase the excerpt length and I ran up against the WordPress wall.

    In order to do it, edit the functions.php and find all the places where "55" is and set it to the new max length (I picked 100) and then add:

    add_filter('excerpt_length', 'my_excerpt_length');
    function my_excerpt_length($length) {
    return 100; // Or whatever you want the length to be.
    }

    Which I found from this page;

    Better would be to create a variable, say, $max_excerpt_length and insert that into the relevant places in functions.php.

  2. Doodlebee
    Member
    Posted 5 years ago #

    You mean use something like this in your *theme* functions.php 9ratehr than edit core code), right?

    function fix_the_excerpt($text) {
      return str_replace('[...]', '...', $text);
    }
    add_filter('the_excerpt', 'fix_the_excerpt');
    
    function my_excerpt_length($length) {
      return 20; // Or whatever you want the length to be.
    }
    add_filter('excerpt_length', 'my_excerpt_length');

    Alternatively, you could use this plugin.

  3. buddha trance
    Member
    Posted 5 years ago #

    @doodlebee - Thank you for your great solution! I don't like editing core files either (better to have a smooth upgrade without having to remember stuff months later) and the theme functions.php code is perfect. :-)

Topic Closed

This topic has been closed to new replies.

About this Topic