Created
June 28, 2014 07:26
-
-
Save palpalani/f701f483eff0314a6d60 to your computer and use it in GitHub Desktop.
WordPress - Stripping Shortcodes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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