• I’m trying to apply a filter to ‘the_excerpt’ in my syntax hiliter plugin so that the excerpts on the category/archive/search pages also have syntax hilited code.

    so here’s the code for applying & removing some filters that I’m using

    // disable wptexturize filter
    remove_filter('the_content', 'wptexturize');
    remove_filter('the_excerpt', 'wptexturize');
    // add conditional wptexturize
    add_filter('the_content', 'dis_en_frmt');
    add_filter('the_excerpt', 'dis_en_frmt');
    // apply filter for syntax hiliting
    add_filter('the_content', 'syntax_hilite', 2);
    add_filter('the_excerpt', 'syntax_hilite', 2);

    Now the problem with the above is that the code is highlighted on the pages where full content is displayed, like main page & post pages, but the Category/Archive/Search pages which use ‘the_excerpt’ don’t have syntax hilighting!! seems that the filter is not being applied. but if I comment the second last line in the above code(commenting out the filter to be applied on ‘the_content’), the code in the excerpt is hilited, meaning that the filter is applied!!

    so what can be this problem? I’m testing this on WP1.5.1

    can anyone help?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter Amit Gupta

    (@amit)

    no-one?

    Ugh, the excerpt filter path is a weird one. Take a look at the code used to generate the excerpt and you’ll see that the filter the_content also gets involved *if* there is no excerpt saved in the database.

    Check out Michel Fortin’s analysis for more details.

    Thread Starter Amit Gupta

    (@amit)

    the filter the_content also gets involved *if* there is no excerpt saved in the database

    yes, I know that if no excerpt is specified then a part of content is used & displayed as excerpt.

    I forgot to add, that’s what’s happenening, as I didn’t save any excerpt, so a part of content is displayed as excerpt. So does that mean that the filter is applied to the_content first & then to the_excerpt, so its doing it twice?

    have you tried filtering get_the_excerpt instead of the_excerpt? that’s what I do in my cg-quickphp plugin, due to my reading of the code and some quick tests. I could be wrong!

    -d

    Yes, in either case (whether you filter on ‘the_excerpt’ or ‘get_the_excerpt’) the function wp_trim_excerpt() will create the excerpt based on the content. To do this it will first apply the filter ‘the_content’.

    Thread Starter Amit Gupta

    (@amit)

    @david:
    I’ve tried that, no good!! Its the same problem as darkcanuck says. I think that it needs to be said that WP should have conditional filter applications, meaning that if ‘the_excerpt’ or ‘get_the_excerpt’ are applied & if the excerpt is created from ‘the_content’ then any filters on ‘the_content’ should not be applied & only ‘the_excerpt’ or ‘get_the_excerpt’ filters should be applied as ‘the_content’ is not being used as itsself there, its merely acting as a conduit for ‘the_excerpt’/’get_the_excerpt’ to generate an excerpt.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘wierd behaviour with applying filters’ is closed to new replies.