Hi i'm trying to hide a shortcode using hooks, my shortcode is this [abc] I have use this code:

remove_shortcode( 'abc' );

this code above removes the shortcode but when i refresh the page I can see the shortcode text [abc]

how can i hide the text [abc] using hooks?or

I'm using a hook function code, to hide the shortcode on a specific category. I cannot use css to hide this shortcode, because it will affect and hide the other category.


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');
  • I am trying to diable the shortcode on plugin deativation with register_deactivation_hook how can i do that? – Awsme Sandy Feb 28 '18 at 7:57

Your Answer

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