WordPress.org

Ready to get started?Download WordPress

Forums

pass excerpt length through the_excerpt(); (2 posts)

  1. Silly Coyote
    Member
    Posted 1 year ago #

    I want to extend the core functionality for the_excerpt to add excerpt_length and excerpt_more filters right into the function itself, I would like to add this from inside a theme's functions.

    i.e. the_excerpt($length,$readmore);

    Is it possible to add this? is there alternatives?

    p.s. The reason I'd like to add this to my theme is to add multiple the_excerpts() with various lengths and read more buttons.

  2. David Choi
    Member
    Posted 1 year ago #

    There is no way to define alternative length with the_excerpt() function itself, unless you want to override the global length:

    function custom_excerpt_length( $length ) {
    	return 20;
    }
    add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );

    as stated on http://codex.wordpress.org/Function_Reference/the_excerpt
    the solution is to creat it from scratch or use global variable. But eaiser solution will be using

    http://wordpress.org/plugins/advanced-excerpt/

Topic Closed

This topic has been closed to new replies.

About this Topic