联系表单7自动添加了p标签

时间:2015-09-12 14:26:11

标签: wordpress contact-form-7

我在联系表单7编辑器中有下一个代码

<div class="row">
    <div class="col-sm-8 col-sm-offset-2">
        <div class="row">
            <div class="col-sm-4">
                [text* name class:border-field placeholder "Name"]
            </div><!-- End of col -->
            <div class="col-sm-4">
                [email* email class:border-field placeholder "Email"]
            </div><!-- End of col -->
            <div class="col-sm-4">
                [text subject class:border-field placeholder "Subject"]
            </div><!-- End of col -->
        </div><!-- ENd of row -->
    </div><!-- End of col -->
</div><!-- ENd of row -->

<div class="row">
    <div class="col-sm-8 col-sm-offset-2">
        [textarea message class:border-field placeholder "Message"]
    </div>
</div><!-- End of row -->

<div class="row text-center">
    <div clas s="col-sm-12">    
        [submit class:btn class:btn-black-fill class:btn-small "Submit"]  
    </div><!-- End of col -->
</div><!-- End of row -->

问题在于,它几乎在每个元素之后添加了随机p标签,并且当第一个文本字段应该全部内联时,由于某种原因在某些原因上略高于其他两个字段。而且我认为这不是css问题,因为以前我在平面HTML中编码并且所有字段都是内联的,所以我认为它必须是联系表格7的内容。

7 个答案:

答案 0 :(得分:53)

根据Contact Form 7 Docs,你可以禁用&#34; wpautop&#34;对于插件,将以下常量放在 wp-config.php

define( 'WPCF7_AUTOP', false );

答案 1 :(得分:33)

如果编辑wp-config.php不是您的解决方案,则可以使用方便的过滤器。 把它放在functions.php

add_filter('wpcf7_autop_or_not', '__return_false');

答案 2 :(得分:2)

在functions.php文件

中添加
function reformat_auto_p_tags($content) {
    $new_content = '';
    $pattern_full = '{(\[raw\].*?\[/raw\])}is';
    $pattern_contents = '{\[raw\](.*?)\[/raw\]}is';
    $pieces = preg_split($pattern_full, $content, -1, PREG_SPLIT_DELIM_CAPTURE);
    foreach ($pieces as $piece) {
        if (preg_match($pattern_contents, $piece, $matches)) {
            $new_content .= $matches[1];
        } else {
            $new_content .= wptexturize(wpautop($piece));
        }
    }

    return $new_content;
}

remove_filter('the_content', 'wpautop');
remove_filter('the_content', 'wptexturize');

add_filter('the_content', 'reformat_auto_p_tags', 99);
add_filter('widget_text', 'reformat_auto_p_tags', 99);

然后在您的帖子编辑器中用raw短代码

包装您的联系表格7短代码

e.g。

[raw][contact-form-7 id="1" title="Contact Us"][/raw]

答案 3 :(得分:1)

我想说一点,当我们要减少自动P标签形式时,我们应该使用下面的过滤器,然后在function.php中编写打击代码。

add_filter('wpcf7_autop_or_not', '__return_false'); 

答案 4 :(得分:0)

我尝试了很多答案,但无效,所以...
我最终使用简单的CSS专门针对空P标签
形式如下:

.wpcf7-form p:empty { display: none; }

这对我有用,并且是一个简单的解决方案。

答案 5 :(得分:0)

这也有效。使用 WordPress 5.7、PHP 7.4、Contact Form 7 v5.4 进行测试。

<?php
add_filter('wpcf7_autop_or_not', false);

可能在某些情况下(旧版本的 WP、PHP?)需要使用 __return_false 实用程序函数。

答案 6 :(得分:-1)

rnevius回答的后续行动,将其放入 /wp-content/plugins/contact-form-7/wp-contact-form-7.php

if ( ! defined( 'WPCF7_AUTOP' ) ) {
    define( 'WPCF7_AUTOP', false );
}

通常,它已经存在 true 值,在这种情况下,只需将 false 替换为true,就可以了。

相关问题