下面是我非常简单的短代码:
function box_shortcode( $atts, $content = null ) {
extract( shortcode_atts( array(
\'width\' => \'auto\',
\'height\' => \'auto\',
), $atts ) );
return \'<div class="boxy-box" style="width:\'. $width .\'; height:\'. $height .\';" >\'.do_shortcode($content).\'</div>\';
}
add_shortcode(\'box\', \'box_shortcode\');
什么东西
应给出:
<div class="boxy-box" width:auto; height:auto;>something</div>
但事实并非如此。即使是一个空的短代码(没有内容,例如[box][/box])也会给出:
<div class="boxy-box" width:auto; height:auto;><br/></div>
(我不在乎,但不知道br来自哪里)
主要问题是,当我尝试做某事时,我得到了:
<div class="boxy-box" width:auto; height:auto;><br/>something<br/></div>
我知道WP editor会自动格式化文本,并且有“noP”插件,但首先-我使用的是HTML编辑器,其次,为什么该死的WP会将Brs(有时是p)添加到内联代码中O
这不是什么大问题,但我必须获得纯输出,所以:
[box]<h1>Header</h1><div>Content</div>[/box]
将在我的箱子div内提供一个标题和div,没有任何Paragrahs、brs、spans等。
有趣的是,我用h2而不是div有相同的短代码,它没有给出任何brs等。
有时我也会<div class="boxy-box" width:auto; height:auto;></p>$content (...)
[编辑]
我发现了一些评论:
这也快把我逼疯了。如果wordpress过滤了该死的代码并将标签包裹起来,那么使用html/代码模式发布的意义何在?
所以我想这就是问题所在。是否有一种方法可以至少为HTML编辑器启用自动转换功能/