WordPress:简码功能的参数
我正在尝试在 Wordpress 中创建一个短代码,其中使用短代码标签调用的函数将短代码标签作为参数。
所以说我有
<?php
var $shortcode = 'my_shortcode_tag';
add_shortcode( $shortcode, 'my_shortcode_function');
?>
然后我想要 'my_shortcode_function'
知道它被调用的短代码标签。我知道当我在实际帖子中调用短代码时,我可以使用 [my_shortcode_tag tag='my_shortcode_tag']
中的属性,但我希望能够只写 [my_shortcode_tag]< /code> 和我的函数知道它是由该标签调用的。有办法做到这一点吗?
I am trying to create a shortcode in Wordpress, in which the function that is called with the shortcode tag gets the shortcode tag as parameter.
So say I have
<?php
var $shortcode = 'my_shortcode_tag';
add_shortcode( $shortcode, 'my_shortcode_function');
?>
then I want 'my_shortcode_function'
to know the shortcode tag by it was called. I know that I could use attributes as in [my_shortcode_tag tag='my_shortcode_tag']
when I call the shortcode in my actual post, but I want to be able to just write [my_shortcode_tag]
and my function to know that it was called by that tag. Is there a way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它作为短代码函数的第三个参数发送(如短代码 API 中所述)。
例如:
这将输出该函数调用的短代码的名称。
This is sent in as the third argument to a shortcode function (as mentioned in the Shortcodes API).
for example:
this will output the name of the shortcode called for that function.