• Resolved suntower

    (@suntower)


    Maybe I’m not getting something basic about how filters work. Why does the following not work correctly? It -always- returns 55.

    add_filter('excerpt_length', 'new_excerpt_length');
    function new_excerpt_length($length) {
    	if( is_front_page() )
    	  return 55;
    	else
    	  return 100;
    }
    add_filter('excerpt_length', 'new_excerpt_length');

    TIA,

    –JC

Viewing 3 replies - 1 through 3 (of 3 total)
  • suntower firstly remove one of the filters. Secondly, try setting the priority of the filter to 999, for example:

    add_filter('excerpt_length', 'new_excerpt_length', 999);

    Thread Starter suntower

    (@suntower)

    OK, I figured it out… it’s a conceptual thing. I thought the filter was tested once when the -page- was loaded. But in fact, the function fires every time an excerpt is printed to the screen. IOW: it thinks the ‘current page’ is the one of it’s post.

    What I want to do is display some post excerpts as part of a larger page (Latest News!) on one or (FAQs!) on another.

    So for me, the thing to do was test for the page_template.

    Thanks for the replies.

    —JC

    Not a prob, hell even I learned something here, i don’t use that filter much 🙂 Thanks for the info.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Conditional Tag In Excerpt Length Filter?’ is closed to new replies.