wordpress 小部件添加额外的 p 标签 [英] wordpress widget addng extra p tags

查看:23
本文介绍了wordpress 小部件添加额外的 p 标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个像这样的短代码:

function requestaquote($atts, $content = null){提取(shortcode_atts(数组('文本'=>'','链接'=>'','颜色'=>''), $atts));return '<div class="speed-button"><img src="'.get_stylesheet_directory_uri().'/images/request-a-quote.jpg" alt="请求报价"/><p class="requstaquote">'.esc_attr($text).'</p></div><!--speed-button-->';}add_shortcode('quotetext', 'requestaquote');

它正在工作,只是它引入了额外的

</p> 对,如下所示:

<p></p><div class="speed-button">...</div><p></p>

这弄乱了我的格式.

我试过 remove_filter('the_content', 'wpautop');

如何删除这些

对.

解决方案

您可以推迟 wp_autop 因为它在短代码输出之前处理:

remove_filter( 'the_content', 'wpautop' );add_filter('the_content', 'wpautop', 12);

或者使用cleanup_shortcode_fix() 函数:

function cleanup_shortcode_fix($content) {$array = array('<p>[' => '[', ']</p>' => ']', ']<br/>' => ']',']
' => ']');$content = strtr($content, $array);返回 $content;}add_filter('the_content', 'cleanup_shortcode_fix');$string = preg_replace('/<p>s*</p>/', '', $string);add_filter('the_content', 'cleanup_shortcode_fix', 1);

来源:删除自动添加的<p>来自没有文字内容的页面(使用短代码)

I have a short code like this:

function requestaquote($atts, $content = null){
    extract(shortcode_atts(array(
        'text'=>'',
        'link'=>'',
        'colour'=>''
        ), $atts));     
    return '<div class="speed-button"><img src="'.get_stylesheet_directory_uri().'/images/request-a-quote.jpg" alt="request a quote " /><p class="requstaquote">'.esc_attr($text).'</p></div><!--speed-button-->';
}
add_shortcode( 'quotetext', 'requestaquote' );

It's working except that its introducing extra <p></p> pairs like this:

<div class="textwidget">
<p></p>
<div class="speed-button">...</div>
<p></p>
</div>

which is messing up my formatting.

I have tried remove_filter('the_content', 'wpautop');

How do I removed these <p></p> pairs.

解决方案

You can pospone the wp_autop because it processes before the shortcode output:

remove_filter( 'the_content', 'wpautop' );
add_filter( 'the_content', 'wpautop' , 12);

Or use the cleanup_shortcode_fix() function:

function cleanup_shortcode_fix($content) {
    $array = array('<p>[' => '[', ']</p>' => ']', ']<br />' => ']', ']<br>' => ']');
    $content = strtr($content, $array);
    return $content;
}

add_filter('the_content', 'cleanup_shortcode_fix');
$string = preg_replace('/<p>s*</p>/', '', $string);
add_filter('the_content', 'cleanup_shortcode_fix', 1);

Source : Remove auto added <p> from a page that has no literal content (uses shortcodes)

这篇关于wordpress 小部件添加额外的 p 标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆