admin管理员组文章数量:1295940
I'm curious how to process shortcodes in arguments (not nested shortcodes, which are already contemplated)::
function do_foo_shortcode($atts, $content = null) {
extract(shortcode_atts(array(
'bar' => '',
), $atts, 'foo'));
$bar = do_shortcode($bar);
$content = do_shortcode($content);
return "$bar - $content";
}
add_shortcode('foo', 'do_foo_shortcode');
For example in:
[foo bar=[video src="video-source.mp4"]]Hello world![/foo]
generates:
[video - ]Hello world!
How can I consider such cases and how to correctly use them?
I'm curious how to process shortcodes in arguments (not nested shortcodes, which are already contemplated)::
function do_foo_shortcode($atts, $content = null) {
extract(shortcode_atts(array(
'bar' => '',
), $atts, 'foo'));
$bar = do_shortcode($bar);
$content = do_shortcode($content);
return "$bar - $content";
}
add_shortcode('foo', 'do_foo_shortcode');
For example in:
[foo bar=[video src="video-source.mp4"]]Hello world![/foo]
generates:
[video - ]Hello world!
How can I consider such cases and how to correctly use them?
Share Improve this question asked Sep 19, 2018 at 15:13 cbuchartcbuchart 1718 bronze badges 6 | Show 1 more comment1 Answer
Reset to default 1A partial solution I've found so far is to escape the brackets in the initial call, then replace the escaped characters in the do_foo_shortcode
function.
function do_foo_shortcode($atts, $content = null) {
extract(shortcode_atts(array(
'bar' => '',
), $atts, 'foo'));
$bar = str_replace("[", "[", $bar);
$bar = str_replace("]", "]", $bar);
$bar = do_shortcode($bar);
$content = do_shortcode($content);
return "$bar - $content";
}
And calling it as
[foo bar="[video src=video-source.mp4]"]Hello world![/foo]
Of course, this is an incomplete solution since it doesn't allow more than 1-level nesting, and quote marks cannot be used in the inner shortcode. Not to mention how complicate is to write it.
本文标签: Passing a nested shortcode as an argument of another shortcode
版权声明:本文标题:Passing a nested shortcode as an argument of another shortcode? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741612708a2388352.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
src
argument on your own shortcode and then just pass that to the underlying function of the video shortcode, rather than trying to mash them together like this. – Jacob Peattie Commented Sep 19, 2018 at 15:20extract(
calls like the plague – Tom J Nowell ♦ Commented Sep 19, 2018 at 16:10