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

  1. Silly Coyote
    Posted 2 years 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
    Posted 2 years 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


Topic Closed

This topic has been closed to new replies.

About this Topic