Embedder Support Forum

92 Comments in 29 Topics
Embedder Plugin Support Forum » nested shortcode
Author Topic: nested shortcode 7 comments / 7673 views
phil

Hi Make, you mentioned earlier that one shortcode can be nested in the another if only the plugin “call do_shortcode on the contents between their tags”. Can you tell me how to modify current version of embedder so it can be able to parse shortcode in the value? I really want that. Thanks in advance.

moztools

Sure — but if you can you give me an example of what you want to do, that would help.

Do you want to do this:

(1) [shortcode] Some text [embed] More text [/shortcode]

Or this:

(2) [embed] Some text [shortcode] More text [/embed]

I think, from you previous questions, it is (1) — you want to use Embedder embeds inside a shortcode provided by another plugin, correct?

If that is the case, is the text (a) between the tags ([shortcode]…[/shortcode]) in the post text (i.e. did you type it in with the editor) or is it (b) generated by another plugin (i.e. automatically inserted by the plugin)?

If it is (a) then you are in luck. The new parser I will be adding to Embedder in the next version will process all the embed tags before any other shortcodes are processes, which means that embeds nested inside other shortcodes will work automatically.

If it is (b), and the other shortcode is inserting an embed into the text, that will not work at the moment — but there is probably a way to make it work, by delaying the processing of the embeds until *after* the shortcodes are processed, which could be an option.

So if you can give me an example of exactly what you are trying to do, that would help me figure out if the new parser will help you or not.

Mike

phil

Hi, what I want is more like (b). For example, I define a new embedder shortcode [a], and in the value field of [a] I have “some text and some text”. is provided by another plugin and is a form. So by simply putting [a] in my post I want this output “some text (a form) and some text”.

I dont know if it’s possible but thanks anyway.

phil

why [b] is filtered out in my previous comment? I will try another way:

For example, I define a new embedder shortcode [a], and in the value field of [a] I have “some text [b] and some text”. [b] is provided by another plugin and is a form. So by simply putting [a] in my post I want this output “some text (a form) and some text”.

moztools

Okay — thanks Phil, I understand.

Try this:

Your embed is [xyz] and the other plugin’s embed is [form].

In the value for [xyz] put:

“Some text %content% some more text”

(In other words, don’t put [form] in the value, put the attribute %content% there instead.)

Then in your post, you can put [xyz] [form] [/xyz] (but remember to leave a space between the shortcodes or it won’t work!) and then when [xyz] is processed, the nested [form] shortcode will be processed and you will get the form.

That might be a little too messy for you, so if you just want to have one [xyz] tag and keep the [form] in the embed value, you can add a small user function instead.

function my_embed_function($name, $value, $attrs, $content) {
    // This will allow [form] to be processed.
    return do_shortcode($value); 
}

You have to add the function to WordPress — the best place is usually in the functions.php file in your theme, but another plugin will also do. (And remember to add the user function name into the settings of your embed.)

Or, you can wait for the next version of the plugin (sometime in the next two weeks) and because the new parser will process embeds *before* shortcodes, it should work automatically. 🙂

phil

Thanks Mike, both methods work and I like the second one.:)

David

How about just adding a flag to the embed definition:

[x] check this if your embed contains other shortcodes that need to be processed after this embed is expanded

If that option is checked, then call do_shortcode() on the resulting embed string directly.

You could also do it automatically by checking to see if the replacement text contains “[[a-z1-9+-]+]”

These both localize this to your plugin, rather than requiring a function to be added to the theme.

Powered by moztools Instant Forums

Leave a Reply

Your email address will not be published. Required fields are marked *