我有一个自定义的短代码标签,它带有一些属性,我希望能够在新行上显示其属性 - 使其更易读内容编辑:wpautop() - 当shortcode属性在新行上时 - 破坏args数组
[component
attr1 ="value1"
attr2 ="value of the second one"
attr3 ="another"
attr4 ="value"
...
attrN ="valueN"]
这个要求背后的原因是一些属性可能在内容上非常冗长。不幸的是,wpautop()
增加了一些讨厌的额外的标记,打破了args
阵列像这样(使用PHP print_r($args)
):
Array ([0] => attr1 [1] => ="value1"
/> [3] => attr2 = [4] => "value [5] => of [6] => the [7] => second [8] => one"
/> [10] => "" //...and more like this)
我试着属性直列:
[component attr1 ="value1" attr2 ="value of the second one" ="value"... attrN ="valueN"]
和输出如预期的那样:
Array ([attr1] => value1 [attr2] => value of the second one [attr3] => //...and so on)
是否有任何方法来使属性满足和一个无效的额外标记打破$args
阵列?
您是否知道这是由wpautop引起的,因为您试图禁用它?我认为这听起来更像是你有一个shortcode_parse_atts()的问题... –
不知道什么时候wpautop运行,但也许你可以预先运行add_filter,删除短代码换行符。 – hansvedo
@ hansvedo如果我确实记得没错,'wpautop()'在过滤器之前运行,我想我前一阵没有成功尝试过这个过程。也@Calle在这个问题上的更多见解可以在这里阅读:http://wordpress.stackexchange.com/questions/71698/wpautop-when-shortcode-attributes-are-on-new-lines-break-args-array/ 71723#71723 - 我最终写了一个自定义插件,以实现我所需要的,但问题本身仍然没有答案。感谢两个建议,但! – Luca