[wp-hackers] nested shortcode

Viper007Bond viper at viper007bond.com
Wed Jan 21 10:06:49 GMT 2009


Shortcodes are not the best way to do what you are trying to accomplish. Use
a generic the_content filter and just check for the existence of
"[addmyclass]" in the post. If found, regex the images and remove the tag.

On Wed, Jan 21, 2009 at 1:48 AM, Daiv Mowbray <daiv at daivmowbray.com> wrote:

>
> Ok thanx, Otto,
>
> I didn't realize that there are 2 types of response to a shortcode.
> I knew there's various manners to add it,
> I wanted to simply add the tag [addmyclass]
> and activate a search replace in my plugin to add the class="myclass" to
> any image in the post.
>
> Easier for the user to add [addmyclass] than to review in code all images
> and
> have to add class="myclass".
>
> I guess that wrapping a post in [addmyclass]post[/addmyclass] is an option.
>
>
> Also, I had been trying to use : do_shortcode($content)
> as recommended in the docs, as the shortcode search and replace function
> only does a single pass of the post content.
>
> I was getting results with unprocessed shortcode, namely the [caption].
> Perhaps my problem lay elsewhere.
>
> Daiv
>
> On Jan 21, 2009, at 7:37 AM, Otto wrote:
>
>> Why are you returning do_shortcode($content)? It's already doing the
>> shortcodes, you don't need to have it run through them again. Just
>> return the new $content.
>>
>
>
>
>
> On Jan 21, 2009, at 7:41 AM, Otto wrote:
>
>  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.
>>
>
>
> ----------
> Daiv Mowbray
> daiv at daivmowbray.com
> ----------
>
>
>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>



-- 
Viper007Bond | http://www.viper007bond.com/ | http://www.finalgear.com/


More information about the wp-hackers mailing list