Created
November 19, 2015 14:08
-
-
Save ewistrand/8185636c71ca60516f62 to your computer and use it in GitHub Desktop.
WP Extract Shortcode from the_content
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
<?php | |
/** | |
* Use in loop or single, has to access post_content | |
*/ | |
$pattern = get_shortcode_regex(); | |
preg_match('/'.$pattern.'/s', $post->post_content, $matches); | |
if (is_array($matches) && $matches[2] == 'smart_track_player') { | |
$shortcode = $matches[0]; | |
echo do_shortcode($shortcode); | |
} | |
/** | |
* Clean out shortcodes to display correct on podcast singles. | |
* Place in functions.php | |
* Replace the_content() in loop with cl_cleaned_content | |
*/ | |
if( ! function_exists('cl_cleaned_content') ) : | |
function cl_cleaned_content() { | |
$content = strip_shortcodes(get_the_content()); | |
$content = apply_filters('the_content',$content); | |
echo $content; | |
} | |
endif; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment