The remove_all_shortcodes() WordPress PHP function clears all shortcodes from the global shortcode tags.
Usage
To use the remove_all_shortcodes() function, simply call it:
remove_all_shortcodes();
Parameters
- None
More information
See WordPress Developer Resources: remove_all_shortcodes()
Examples
Removing all shortcodes before displaying content
This code snippet removes all shortcodes before displaying the content.
add_filter('the_content', 'remove_all_shortcodes_from_content');
function remove_all_shortcodes_from_content($content) {
remove_all_shortcodes();
return $content;
}
Removing shortcodes when a specific user role views a page
This example removes all shortcodes if the user viewing the page is a subscriber.
add_filter('the_content', 'remove_shortcodes_for_subscribers');
function remove_shortcodes_for_subscribers($content) {
if (current_user_can('subscriber')) {
remove_all_shortcodes();
}
return $content;
}
Removing shortcodes from a custom field
This code snippet removes all shortcodes from a custom field before outputting the field value.
$custom_field_value = get_post_meta(get_the_ID(), 'custom_field_key', true);
remove_all_shortcodes();
echo apply_filters('the_content', $custom_field_value);
Temporarily removing shortcodes before executing custom code
This example temporarily removes all shortcodes, executes custom code, and then restores the original shortcodes.
$original_shortcodes = $GLOBALS['shortcode_tags']; remove_all_shortcodes(); // Custom code here $GLOBALS['shortcode_tags'] = $original_shortcodes;
Removing all shortcodes in a custom post type
This code snippet removes all shortcodes when displaying content in a custom post type called “my_custom_post_type”.
add_filter('the_content', 'remove_shortcodes_for_custom_post_type');
function remove_shortcodes_for_custom_post_type($content) {
if (get_post_type() === 'my_custom_post_type') {
remove_all_shortcodes();
}
return $content;
}