remove_all_shortcodes()WP 2.5.0

Clear all shortcodes.

This function clears all of the shortcode tags by replacing the shortcodes global with an empty array. This is actually an efficient method for removing all shortcodes.

No Hooks.

Return

null. Nothing (null).

Usage

remove_all_shortcodes();

Examples

0

#1 Disable all shortcodes in WordPress

Let's make sure that no shortcodes work in the content. Add a line to the theme file functions.php:

// disable all shortcodes
add_action( 'wp_loaded', function(){
	remove_all_shortcodes();
} );
0

#2 Apply only one custom shortcode (once)

Suppose we need to apply our single shortcode to the passed text. To do this, we can:

  1. Cancel all the shortcodes (previously saving the original data);
  2. Then register our own shortcode;
  3. Apply all the shortcodes to the text (all will contain our single shortcode);
  4. Return the original data of the shortcodes back.
function shortcode_hack( $text ) {
	global $shortcode_tags;

	// save current shortcodes
	$save = $shortcode_tags;

	remove_all_shortcodes();

	add_my_shortcode();

	$text = apply_shortcodes( $text );

	// restore shortcodes
	$shortcode_tags = $save;

	return $text;
}

Notes

  • Global. Array. $shortcode_tags

Changelog

Since 2.5.0 Introduced.

remove_all_shortcodes() code WP 6.5.2

function remove_all_shortcodes() {
	global $shortcode_tags;

	$shortcode_tags = array();
}