• I am filtering the_content to add some stuff to page/post content before displaying it. Problem is, widgets that display content excerpts (like Recent Posts, for example) are ALSO getting filtered and my content added on, which is not desirable. Seems simple, but I can’t seem to work around that. Should I be filtering something else, and not the_content, or is there some way to check if we are in a widget and not filter the content, like is_widget (doesn’t exist that I know of)?

    Thanks.

Viewing 1 replies (of 1 total)
  • In your filter, you can add a check for a global variable that you can turn on and off:

    function my_filter ($content) {
       global $my_global_content_switch;
       if ( !$my_global_content_switch ) return $content;
       // rest of filter code
    }

    Then, in the template:

    $my_global_content_switch = 1;
    the_content();
    $my_global_content_switch = 0;
Viewing 1 replies (of 1 total)
  • The topic ‘Unwanted behaviour: add_filter also processes widget contents!’ is closed to new replies.