WordPress users use shortcodes in the post content for integrating PHP or other type of code between the content and may be a good way to add functionality to the site. But sometimes we need for removing shortcodes from the post content from a specific page or specific post.
We can use following code snippet to remove ALL shortcodes from the post content, just copy and paste the code snippet to the functions.php of your current theme.
Code Snippet
1 2 3 4 5 | function remove_shortcodes($content) { $content = strip_shortcodes($content); return $content; } add_filter('the_content', 'remove_shortcodes'); |
we can remove shortcodes from particular page, e.g single Page
Code Snippet
1 2 3 4 5 6 7 | function remove_shortcodes($content) { if(is_single()) $content = strip_shortcodes($content); return $content; } add_filter('the_content', 'remove_shortcodes'); |
Removing a specific shortcode from the post content
Code Snippet
1 2 3 4 5 6 7 8 9 10 11 12 | function remove_shortcodes($content) { // wordpress function provides a regex to get any shortcode from your content $pattern = get_shortcode_regex(); preg_match('/'.$pattern.'/s', $content, $matches); if ( isset($matches[2]) && is_array($matches) && $matches[2] == 'recent_widget') { $content = str_replace( $matches['0'], '', $content ); } return $content; } add_filter('the_content', 'remove_shortcodes'); |