[wp-hackers] Show only Shortcodes in Sidebar
Andy Skelton
skeltoac at gmail.com
Mon Oct 26 12:33:58 UTC 2009
>> > How to filter the_content so that only shortcodes display in that sidebar
>> > and rest of content gets filtered out?
>>
>> $content = strip_shortcodes($post->post_content);
>>
> This does the reverse. It removes the shortcodes. I want to display the
> shortcodes only and anything except shortcodes should be filtered out.
Sorry, I flipped a bit. Look at the source for strip_shortcodes. It
gets the regex pattern from get_shortcode_regex(). You can use that in
preg_replace. Something like this extempore and untested snippet:
$pattern = get_shortcode_regex();
$pattern = str_replace('(.?)', '', $pattern);
$pattern = str_replace('2', '3', $pattern);
$content = $post->post_content;
$shortcodes = preg_replace("/.*($pattern).*?/s", '$1', $content);
Andy
More information about the wp-hackers
mailing list