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 [code]strip_shortcodes()[/code] 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.
[cc lang=”php”]
function remove_shortcodes($content)
{
// Removing Shortcodes
$content = strip_shortcodes( $content );
return $content;
}
// Registering the filter
add_filter(‘the_content’, ‘remove_shortcodes’);
[/cc]
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.
I need to ask something related to wordpress. I have downloaded a theme from free theme site and now want to create a website. I like the whole theme except one side bar. I have another theme which has wonderful sidebar. So how can i change the sidebar of both these theme with each other?
[…] Shortcode is one of the very good feature of the wordpress. With this shortcodes we can format our content as we need. PHP Read the original post on DZone… […]
So if I add this to my code, will that only remove the code without removing the functionality of my shortcodes or in other words will my shortcodes still work without being visible to someone viewing my page source code?