Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- RE: http://wpthemetutorial.com/2012/02/14/removing-a-specific-shortcode-from-the_content/
- Thank you for posting this. I have spent most of my afternoon trying to figure out how to efficiently see if a post had a shortcode in it. In my case, I needed to put an image in the RSS Excerpt... with variables from the shortcode. Here's my code for anyone is a simular situation:
- */
- add_filter('the_excerpt_rss', 'rssexcerpt');
- function rssexcerpt($rss_content) {
- global $post;
- $regex_pattern = get_shortcode_regex();
- preg_match('/'.$regex_pattern.'/s', $post->post_content, $regex_matches);
- if ($regex_matches[2] == 'YOUR_SHORTCODE') {
- $atts = str_replace(" ", "", $matches[3]); // this is some sort of invisible char that's not a space
- $atts = str_replace(" ", "&", $atts);
- $atts = str_replace('"', '', $atts);
- parse_str($atts, $atts);
- $rss_content = YOUR_SHORTCODE_FUNCTION($atts).$rss_content;
- }
- return $rss_content;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement