我目前正在为我正在开发的wordpress主题创建短代码。我希望它是尽可能友好的用户,目前我发现,当我使用段落来分离的短代码在wordpress编辑器,它添加了不必要的<p></p>代码。
例如,当我在WP编辑器中键入以下内容时:
[container]
[row]
[one_half]1st Half[/one_half]
[one_half]2nd Half[/one_half]
[/row]
[/container]我在前端得到了这个结果:
<section class="wrapper special container style3"></p>
<p><div class="row"></p>
<p><div class="6u"><section>1st Half</section></div></p>
<p><div class="6u"><section>2nd Half</section></div></p>
<p></div></p>
<p></section>然而,如果我写这个:
[container][row][one_half]1st Half[/one_half][one_half]2nd Half[/one_half][/row][/container] 它的correct....like如下:
<section class="wrapper special container style3">
<div class="row">
<div class="6u">
<section>1st Half</section>
</div>
<div class="6u">
<section>2nd Half</section>
</div>
</div>
</section>下面是我的短代码的php (上面提到的三个):
// Container
function container($atts, $content = null) {
$return_string = '<section class="wrapper special container style3">'. do_shortcode($content) .'</section>';
wp_reset_query();
return $return_string;
}
// Row
function row($atts, $content = null) {
$return_string = '<div class="row">'. do_shortcode($content) .'</div>';
wp_reset_query();
return $return_string;
}
function one_half($atts, $content = null) {
$return_string .= '<div class="6u">';
$return_string .= '<section>'. do_shortcode($content) .'</section>';
$return_string .= '</div>';
wp_reset_query();
return $return_string;
}
function register_shortcodes(){
add_shortcode('row', 'row');
add_shortcode('one_half', 'one_half');
add_shortcode('container', 'container');
}
add_action( 'init', 'register_shortcodes');我想要的是能够像第一个示例那样在wp编辑器中编写我的短代码(因为这样对用户来说更自然),但是输出的代码与第二个示例一样正确。有办法做到这一点吗?
https://stackoverflow.com/questions/23287232
复制相似问题