Using WordPress ‘remove_shortcode()’ PHP function

The remove_shortcode() WordPress PHP function removes the specified shortcode hook.

Usage

To remove a shortcode, call the function with the shortcode tag as the argument:

remove_shortcode('your_shortcode_tag');

Parameters

  • $tag (string) – Required. The shortcode tag to remove the hook for.

More information

See WordPress Developer Resources: remove_shortcode()

Examples

Removing a Custom Shortcode

Remove a custom shortcode after adding it:

// Add a custom shortcode
add_action('init', 'my_add_shortcodes');
function my_add_shortcodes() {
    add_shortcode('myShortcode', 'my_shortcode_function');
}

// Remove the custom shortcode
add_action('init', 'remove_my_shortcodes', 20);
function remove_my_shortcodes() {
    remove_shortcode('myShortcode');
}

Removing Shortcodes on Specific Pages

Remove shortcodes if they appear on specific pages:

function prefix_remove_shortcode_trigger_on_specific_pages() {
    // Page IDs where we want to remove shortcodes
    $page_ids = array(22, 2599);

    // Array of shortcode tags to be removed
    $shortcodes_to_remove = array('my_shortcode_1', 'someone_other_shortcode');

    if (in_array(get_the_ID(), $page_ids)) {
        foreach ($shortcodes_to_remove as $shortcode_tag) {
            remove_shortcode($shortcode_tag);
        }
    }
}
add_action('the_post', 'prefix_remove_shortcode_trigger_on_specific_pages', 20);

Removing a Shortcode from a Plugin

Remove a shortcode added by a plugin:

function remove_plugin_shortcode() {
    remove_shortcode('plugin_shortcode_tag');
}
add_action('init', 'remove_plugin_shortcode');

Removing a Shortcode from a Theme

Remove a shortcode added by a theme:

function remove_theme_shortcode() {
    remove_shortcode('theme_shortcode_tag');
}
add_action('init', 'remove_theme_shortcode');

Removing All Shortcodes

Remove all registered shortcodes:

function remove_all_shortcodes() {
    global $shortcode_tags;
    $shortcode_tags = array();
}
add_action('init', 'remove_all_shortcodes', 100);