1

I need to disable wpautop for some shortcodes. I've read the following on how to disable it:

However these apply to wpautop in general.

I want to only disable it for specific shortcodes, because some shortcodes in my theme rely on that wpautop in order to work.

1

Well, there is a script out there. The author claims that it removes the wpautop form individual specific shorcodes. You'll find it here.

Add this to your functions.php or your plugin like below-

// Here I assumed that you kept the name of the PHP script file same 
include "shortcode-wpautop-control.php";

And then call the function ike below-

chiedolabs_shortcode_wpautop_control(
    array(
        'your_short_code'
    )
);

You can also call it like this-

// Create first the array of shortcodes from which you wanna remove `wpautop`
$array_of_shortcodes = [ 
    '1st_shortcode', 
    '2nd_shortcode', 
    '3rd_shortcode', 
];
// Then pass the array as parameter when you're calling the function
chiedolabs_shortcode_wpautop_control( $array_of_shortcodes );

Please note that, this solution isn't tested. Test it before going to production.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.