remove_all_shortcodes()
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
#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(); } );
#2 Apply only one custom shortcode (once)
Suppose we need to apply our single shortcode to the passed text. To do this, we can:
- Cancel all the shortcodes (previously saving the original data);
- Then register our own shortcode;
- Apply all the shortcodes to the text (all will contain our single shortcode);
- 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() remove all shortcodes code WP 6.7.1
function remove_all_shortcodes() { global $shortcode_tags; $shortcode_tags = array(); }