check if FILTER(“the_content”) is being executed in `the_post()`

I want to use

add_filter('the_content',...........)

however, I want that filter only to affect main post’s content. See phseudo-example:

<html>
.......
<meta decsription>.....the_content...</meta>
.......
<left_widget>....the_content...</left_widget> 
.......
<MAIN_POST>....the_content...</MAIN_POST>         <----------------- I want only this to be affected
......

How to achieve? (of course, out-of-question is the category pages, where post_contents are listed)

5 Answers
5

Found solution here, to use in_the_loop() (but read comment below my answer too):

add_filter( 'the_content', 'custom_content' );

function custom_content( $content ) {
    if ( in_the_loop() ) {
        // ....
    }
    return $content;
}

Leave a Comment