[wp-hackers] nested shortcode

Otto otto at ottodestruct.com
Wed Jan 21 06:41:56 GMT 2009


On Sat, Jan 17, 2009 at 5:58 PM, Daiv Mowbray <daiv at daivmowbray.com> wrote:
> I add a shortcode [myclass] anywhere in a post
> which will then add to any image in that post the class of myclass.
>
> remember that a post image probably has [caption] shortcode already.
>
> I have (inside my plugin class):
> add_shortcode ( 'myclass' , array(&$this, 'class_shortcode_out'));

Also, remember that there's two types of shortcodes.

1. Something like [gallery], which simply gets replaced with a bunch of content.
2. Something like [caption]<img whatever>[/caption], which adds stuff
to the existing content.

If you're simply adding [myclass] in the post, then I your $content
will be empty, since you're not surrounding anything, thus using the
first type of shortcode. Shortcodes only get the content that they
enclose. Not the whole post.

-Otto


More information about the wp-hackers mailing list