remove_shortcode( string $tag )

Removes hook for shortcode.


Description Description


Parameters Parameters

$tag

(string) (Required) Shortcode tag to remove hook for.


Top ↑

Source Source

File: wp-includes/shortcodes.php

function remove_shortcode( $tag ) {
	global $shortcode_tags;

	unset( $shortcode_tags[ $tag ] );
}

Top ↑

Changelog Changelog

Changelog
Version Description
2.5.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by Aurovrata Venet
    //add a custom shortcode 
    add_action( 'init', 'my_add_shortcodes' );
    function my_add_shortcodes() {
    	add_shortcode( 'myShortcode', 'my_shortcode_function' );
    }
    //which can also remove 
    add_action( 'init', 'remove_my_shortcodes',20 );
    function remove_my_shortcodes() {
    	remove_shortcode( 'myShortcode' );
    }
    
  2. Skip to note 2 content
    Contributed by raoabid491
    /**
     * Remove shortcodes if we are on some specific page
     */
    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 );

You must log in before being able to contribute a note or feedback.