I am filtering the content with the the_content
filter. Everything works perfect, excerpt that my changes are applied to custom queries as well. My changes appear in the sidebar as well if the widget uses a custom query
To counter that, I’m using is_main_query()
to target the main query only, but it is not working. Changes are simply still applied to all queries through out. What is funny though, all other conditional checks like is_single()
and is_category()
is working if I target specific pages, except that all changes affect any other custom query on that page, whether I use is_main_query()
or not
Am I missing something here. How do I apply my changes to the main query only using the the_content
filter
add_filter('the_content', 'custom_content');
function custom_content($content){
if(is_main_query()){ // << THIS IS NOT WORKING
// My custom content that I add to the_content()
}
return $content;
}