如果你mixed self-closing and enclosing shortcodes for the same tag/shortcode, e、 g.您将有问题的短代码放在相同的帖子内容中,如下所示:
1) Self-closing: [test content="foo" ] and 2) Enclosing: [test]blabla[/test]
.. 在这种情况下,WordPress的短代码解析器会将这两个短代码视为只有一个短代码,即它开始于
[test content="foo" ] 结束于
[/test], 因此
$content 价值将是
and 2) Enclosing: [test]blabla.
因此,尝试创建一个全新的帖子,只添加上述短代码中的一个,例如。just the [test]blabla[/test], 然后你会得到预期的输出,即。AblablaB.
看见https://codex.wordpress.org/Shortcode_API#Enclosing_vs_self-closing_shortcodes 了解更多详细信息。
如果您想在自动关闭和封闭表单中使用您的短代码,那么您可以通过使用/ 如中所示[test /] (或[test/]), 其功能与/ 在自动关闭HTML标记中,如<br />, <hr />, <img ... />, 等
例如,(注意/])
1) Self-closing: [test content="foo" /] and 2) Enclosing: [test]blabla[/test]
.. 这样,您就可以得到正确的输出-
1) Self-closing: AbarB and 2) Enclosing: AblablaB.
对于[test /] (或只是[test] 未与封闭形式混合时),或[test][/test] (附件形式),基于代码的正确输出实际上是AB 而不是ANot loadingB.
因为使用的快捷码没有任何内容,其中;“内容”;此处指的是开头和结尾标记之间的内容,例如。[test]this is the CONTENT[/test].
其次,短代码没有content 属性/参数(例如[test content="foo"]), 因此$content 保持为空,然后输出AB.
如果你真的想要Not loading 永远是$content 当内容和content 属性都为空或未指定,则可以执行以下操作。。
$content = $content ? $content : \'Not loading\'; // add this line
return \'A\' . $content . \'B\';
那样的话,
[test /] 和
[test][/test] 会给你
ANot loadingB.