Stop parsing shortcodes

I’d like to stop parsing shortcodes in the_content but I’m struggling to find what the correct filter would be. This didn’t work:

remove_filter( 'the_content', 'do_shortcode', 40 );
remove_filter( 'the_content', 'run_shortcode', 40 );
remove_filter( 'the_content', 'wpautop', 40 );
remove_filter( 'the_content', 'autoembed', 40 );
remove_filter( 'the_content', 'prepend_attachment', 40 );

This worked (but also disabled all other useful filters):

remove_all_filters( 'the_content', 40 );

So, I’d like to disable autoembed and do_shortcode and let WordPress display them as plain text. Would it be possible? I’m using wp hook in main plugin’s PHP file.

1 Answer
1

The correct way is calling remove_filter with the same priority as the hook was added:

remove_filter( 'the_content', 'do_shortcode', 11 );

Some plugins change this filter’s priority, so you could clear the global list of registered shortcodes temporary:

add_filter( 'the_content', 'toggle_shortcodes', -1 );
add_filter( 'the_content', 'toggle_shortcodes', PHP_INT_MAX );

function toggle_shortcodes( $content )
{
    static $original_shortcodes = array();

    if ( empty ( $original_shortcodes ) )
    {
        $original_shortcodes = $GLOBALS['shortcode_tags'];
        $GLOBALS['shortcode_tags'] = array();
    }
    else
    {
        $GLOBALS['shortcode_tags'] = $original_shortcodes;
    }

    return $content;
}

Leave a Comment