Shortcode is one of the very good feature of the wordpress. With this shortcodes we can format our content as we need. But what if you don’t want to format your content as your shortcode and display just original content??
Are you going to remove all your short code using some regular expression or what? Wait for a minute, Here is the way with which you can remove all your shortcode from the content.
WordPress has given one filter for the same with which we can remove all the shortcodes from the content. We will use the function strip_shortcodes() which make this trick possible.
All you need to do is just register this filter to the_content and make the custom function which do this trick. As mentioned above we will use strip_shortcodes() function for this.
Have a look at below code block for the same.
{
// Removing Shortcodes
$content = strip_shortcodes( $content );
return $content;
}
// Registering the filter
add_filter('the_content', 'remove_shortcodes');
You need to place above code in functions.php of your active theme. If you want to make this trick work for certain pages then you can place the conditions in the function remove_shortcodes().
By placing above code in functions.php will remove all shortcode from the content in whole site.
I have to use this trick for one of my project where I want to show shortcode in detail page only. Hope this will be useful to you also.
Subscribe to our RSS feed for More WordPress Tricks.
Pingback: Remove All Shortcodes in WordPress | PHP | Syngu