Skip to content

Instantly share code, notes, and snippets.

@ewistrand
Created November 19, 2015 14:08
Show Gist options
  • Save ewistrand/8185636c71ca60516f62 to your computer and use it in GitHub Desktop.
Save ewistrand/8185636c71ca60516f62 to your computer and use it in GitHub Desktop.
WP Extract Shortcode from the_content
<?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