add_filter for specific pages

It is helpful to post your entire filter and callback code, rather than just pieces.

But, I suspect that the problem is that you’re not returning $the_content outside of your conditional, e.g.:

function magicalendar_get_event_page( $content ) {
    if ( $post->post_name == 'magicalendarpage' ) {
        // Do something to $content
        return $content;
    }
}
add_filter( 'the_content', 'magicalendar_get_event_page' );

If that’s the case, move the return outside the conditional:

function magicalendar_get_event_page( $content ) {
    if ( $post->post_name == 'magicalendarpage' ) {
        // Do something to $content
    }
    return $content;
}
add_filter( 'the_content', 'magicalendar_get_event_page' );

To know why/how it’s interfering with other filters on 'the_content', we probably need to see your code.

EDIT

At least two problems:

  1. You’re not passing $content as an argument to your filter callback
  2. DO NOT ECHO FILTER OUTPUT! Return it. That is very likely causing your problem with other filters applied to the_content.

If you need to filter the_content specifically before or after other filters, then add a priority to your add_filter() call. 10 is the default. Use a lower number to filter sooner; use a higher number to filter later.

Leave a Comment