0

I am tring to set a different excerpt lenght for the pages that use an specific page templates using excerpt_length filter. This is the code:

add_filter( 'excerpt_length', 'nmd_excerpt_length', 999 );
if ( !function_exists('nmd_excerpt_length') ) {
    function nmd_excerpt_length( $length ) {
        global $nmd_opt;
        return ( is_page_template('templates/masonry.php') ) ? $nmd_opt['masonry_excerpt_lenght'] : $nmd_opt['excerpt_lenght'];
    }
}

But this show the same excerpt on masonry.php as on the other pages, like it return false. I am using is_page_template('templates/masonry.php') in other parts of my functions.php and it works well. Also I have tried with other conditionals tag like is_page_template('templates/homepage.php') or is_home() and it works well too.

Why doesn't work is_page_template('templates/masonry.php') inside the filter? What I am doing wrong?

  • Have you read the Codex page for is_page_template? – Milo Oct 5 '14 at 15:41
  • Yes, I know this cannot be used inside the loop, but this case is "inside the loop"? If yes, why it works with is_page_template('templates/homepage.php')? – ThemesCreator Oct 5 '14 at 15:43
  • Yes, this case is inside the Loop. Who knows, without rebuilding your template setup. Respectively. :) – Rarst Oct 5 '14 at 16:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.