How To Ignore a Filter On Applying Filter the Content In a Function

You can temporarily detach the function from the hook.

    // THIS IS MY PROBLEM LINE, i USE Apply Filters for post content....

    $priority = has_filter('the_content', ['TableOfContents', 'writeTOC'] );
    if ( $priority !== false )
        remove_filter('the_content', ['TableOfContents', 'writeTOC'], $priority );

    $meta = apply_filters('the_content', $post->post_content);

    if ( $priority !== false )
        add_filter('the_content', ['TableOfContents', 'writeTOC'], $priority );


    $meta = strip_tags($meta);
    $meta = strip_shortcodes($meta );

Codex:

Leave a Comment