Using WordPress ‘remove_shortcode()’ PHP function

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


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



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

More information

See WordPress Developer Resources: remove_shortcode()


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() {

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) {
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() {
add_action('init', 'remove_plugin_shortcode');

Removing a Shortcode from a Theme

Remove a shortcode added by a theme:

function remove_theme_shortcode() {
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);