remove_all_shortcodes()
Removes all registered shortcodes.
This function clears all shortcodes by replacing the global shortcode variable with an empty array. This is the most efficient way to remove all shortcodes.
More details about shortcodes.
No Hooks.
Returns
null. Returns nothing.
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.9.1
function remove_all_shortcodes() {
global $shortcode_tags;
$shortcode_tags = array();
}