Instead of removing the shortcode, re-register it with a function that returns an empty string (or something that casts to an empty string). You can use the built in __return_empty_string
. This will replace whatever the original callback was with something that just replaces the shortcode with nothing.
// sometime after the first call to add_shortcode
add_shortcode('abc', '__return_empty_string');
If you control the original shortcode function, adding a way to shortcircuit the shortcode and stop processing is a good way to go:
add_shortcode('abc', 'wpse205424_shortcode');
function wpse205424_shortcode($args)
{
if (apply_filters('wpse205424_disable_shortcode', false)) {
return '';
}
// rest of the shortcode as normal here.
}
Then somewhere else in your code you can check for the reason to disable the shortcode and hook into your filter.
if (shortcodeShouldBeDisabledForSomeReason()) {
add_filter('wpse205424_disable_shortcode', '__return_true');
}