Skip to content

Instantly share code, notes, and snippets.

@palpalani
Created June 28, 2014 07:26
Show Gist options
  • Save palpalani/f701f483eff0314a6d60 to your computer and use it in GitHub Desktop.
Save palpalani/f701f483eff0314a6d60 to your computer and use it in GitHub Desktop.
WordPress - Stripping Shortcodes
There might be some cases that you need the shortcodes of the text to be omitted: You may use part of the content for a "Next Post" preview, you may have switched to a new theme and don't want to display texts of shortcodes that are not run anymore, and so on.
When that time comes, strip_shortcodes() is your friend.
Usage
There's a very good example in the Codex. Let's say that you need to strip shortcodes in the homepage but let them run in other content pages.
Here's how you should use the strip_shortcodes() function:
<?php
function remove_shortcode_from_index( $content ) {
if ( is_home() )
$content = strip_shortcodes( $content );
return $content;
}
add_filter( 'the_content', 'remove_shortcode_from_index' );
?>
Quick and easy.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment