括起来的短码中的额外段落标签

时间:2016-09-25 作者:Chris Pink

我有一个创建列的快捷代码,编辑器(文本视图)中的页面如下所示;

[two-column]<ul>
    <li>Annual statutory accounts preparation</li>
    <li>Independent Examination service</li>
    <li>Audit file preparation</li>
    <li>Gift Aid returns</li>
    <li>Payroll</li>
</ul>[/two-column]
[two-column]<ul>
    <li>Bookkeeping service</li>
    <li>Management accounts</li>
    <li>Charity Commission administration service</li>
    <li>OSCR administration service</li>
    <li>Companies House administration service</li>
</ul>[/two-column]
不幸的是,当它出现在页面上时,它是这样的;

<p><div class="two-column">
<ul>
<li>Annual statutory accounts preparation</li>
<li>Independent Examination service</li>
<li>Audit file preparation</li>
<li>Gift Aid returns</li>
<li>Payroll</li>
</ul>
<p></div><br />
<div class="two-column">
<ul>
<li>Bookkeeping service</li>
<li>Management accounts</li>
<li>Charity Commission administration service</li>
<li>OSCR administration service</li>
<li>Companies House administration service</li>
</ul>
<p></div></p>
</div>
现在我不想删除所有<p> 标记(通过操纵wpautop),那么如何处理此短代码。

短代码;

function column_shortcode($atts = [], $content = null)
{
   $content = \'<div class="two-column">\'.$content.\'</div>\';

   return $content;
}

add_shortcode(\'two-column\', \'column_shortcode\');

1 个回复
SO网友:Chris Pink

好吧,似乎有人走了这条路,事实上。。。。shortcode_unautop()

工作完成。它在编辑器中看起来很优雅,在输出中起作用。

现在的短代码如下所示;

function column_shortcode($atts = [], $content = null)
{
   $content = \'<div class="two-column">\'.$content.\'</div>\';

   $content = shortcode_unautop($content);

   return $content;
}

add_shortcode(\'two-column\', \'column_shortcode\');

相关推荐

SHORTCODE_ATTS()中的$ATTS参数是什么?

这个WordPress developers reference page for shortcode_atts() 国家:$atts(array)(必选)用户在shortcode标记中定义的属性。但我不理解这个定义。例如,在WP Frontend Profile 插件:$atts = shortcode_atts( [ \'role\' => \'\', ], $atts ); 据我所知,shortcode\