[wp-hackers] Show only Shortcodes in Sidebar

Navjot Singh navjotjsingh at gmail.com
Mon Oct 26 12:39:48 UTC 2009


Thnx, this code does show the shortcodes, but how to reparse the shortcodes.
Afterall I want the shortcodes values (i.e. the videos) to show in sidebar.
do_shortcode($shortcodes) does not help.

Sent from Delhi, DL, India

On Mon, Oct 26, 2009 at 6:03 PM, Andy Skelton <skeltoac at gmail.com> wrote:

> >> > 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
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


More information about the wp-hackers mailing list