[英]Wordpress Function Within a Shortcode
In brief, I am trying to effectively insert a PHP function into the shortcode and having no luck. 简而言之,我正在尝试将PHP函数有效地插入简码中,并且没有运气。
The shortcode: 简码:
[res_map address=""]
The function: 功能:
<?php the_field('address'); ?>
What I have so far: 到目前为止,我有:
<?php echo do_shortcode('[res_map address="' . the_field("address") . '"]'); ?>
Any help on how to properly do this will be highly appreciated. 任何有关如何正确执行此操作的帮助将不胜感激。
You may try something like this 您可以尝试这样的事情
$ret = the_field("address");
echo do_shortcode('[res_map address = "'. $ret .'"]');
In this case, your function must return a string, ie 在这种情况下,您的函数必须返回一个字符串,即
function the_field($arg)
{
// ...
return 'something';
}
Because do_shortcode function expects string
as it's argument and it's required. 因为do_shortcode函数期望
string
作为参数,所以它是必需的。 For example, it should be something like this 例如,应该是这样的
echo do_shortcode('[res_map address = "something"]');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.