Wordpress相同类型的嵌套短代码

Wordpress相同类型的嵌套短代码,wordpress,Wordpress,-正如您在这里看到的,短代码如下: [tag-a] [tag-a] [/tag-a] [/tag-a] 这是行不通的。我看不出有任何解释。因此,我的问题是如何在wordpress中创建相同类型的嵌套短代码,以及是否可能?您可以为同一短代码创建不同的别名 add_shortcode('tag','my_shortcode_function'); add_shortcode('sub-tag','my_shortcode_function'); function my_shortcod

-正如您在这里看到的,短代码如下:

[tag-a]
   [tag-a]
   [/tag-a]
[/tag-a]

这是行不通的。我看不出有任何解释。因此,我的问题是如何在wordpress中创建相同类型的嵌套短代码,以及是否可能?您可以为同一短代码创建不同的别名

add_shortcode('tag','my_shortcode_function');
add_shortcode('sub-tag','my_shortcode_function');
function my_shortcode_function($atts,$content) {
    // do things here
}
然后像这样使用它

[tag]
  [sub-tag]
  [/sub-tag]
[/tag]

它们将做同样的事情,但解析器将知道如何关闭它们。

这是do_shortcode()使用的上下文无关regexp解析器的一个限制-它非常快,但不计算嵌套级别,因此在这些情况下,它无法将每个开始标记与其正确的结束标记相匹配。