[英]Contact Form 7 auto added p tags
I have next code inside contact form 7 editor我在联系表格 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 -->
The problem is that it adds random p tags almost after each element and also that first text field is for some reason little bit above other two fields when they should all be inline.问题是它几乎在每个元素之后添加了随机的 p 标签,而且第一个文本字段由于某种原因而略高于其他两个字段,而它们都应该是内联的。 And i think this is not css problem because previously i had this coded in plane HTML and all fields were inline so i think it must be something with contact form 7.
而且我认为这不是 css 问题,因为以前我在平面 HTML 中对此进行了编码,并且所有字段都是内联的,因此我认为它必须与联系表格 7 相关。
根据Contact Form 7 Docs ,您可以通过在wp-config.php 中放置以下常量来禁用插件的“wpautop”:
define( 'WPCF7_AUTOP', false );
If editing wp-config.php
is not the solution for you, there's a handy filter.如果编辑
wp-config.php
不是您的解决方案,那么有一个方便的过滤器。 Put it in your functions.php
:把它放在你的
functions.php
:
// Remove <p> and <br/> from Contact Form 7
add_filter('wpcf7_autop_or_not', '__return_false');
我想说一下,当我们想要减少自动 P 标签形式时,我们应该使用下面的过滤器,只需在 function.php 中编写代码。
add_filter('wpcf7_autop_or_not', '__return_false');
I tried many answers but nothing worked so...我尝试了很多答案,但没有任何效果,所以......
I ended up using simple CSS to specifically target empty P tags我最终使用简单的 CSS 专门针对空的 P 标签
in the form itself like this:以这样的形式本身:
.wpcf7-form p:empty { display: none; }
This worked for me and, its a simple solution.这对我有用,而且是一个简单的解决方案。
Add this in your functions.php file将此添加到您的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);
Then on your post editor wrap your contact form 7 shortcode with raw
shortcode然后在您的帖子编辑器上用
raw
短代码包装您的联系表格 7 短代码
eg例如
[raw][contact-form-7 id="1" title="Contact Us"][/raw]
This works too.这也有效。 Tested with WordPress 5.7, PHP 7.4, Contact Form 7 v5.4.
使用 WordPress 5.7、PHP 7.4、联系表 7 v5.4 进行测试。
<?php
add_filter('wpcf7_autop_or_not', false);
Potentially there are situations (old versions of WP, PHP?) where using the __return_false
utility function is necessary.在某些情况下(旧版本的 WP、PHP?),可能需要使用
__return_false
实用程序函数。
Follow-up to rnevius answer, put this in /wp-content/plugins/contact-form-7/wp-contact-form-7.php rnevius回答的后续行动,将其放在/wp-content/plugins/contact-form-7/wp-contact-form-7.php中
if ( ! defined( 'WPCF7_AUTOP' ) ) {
define( 'WPCF7_AUTOP', false );
}
Normally, it's already there with a true value, in that case, just replace false by true and you're good to go. 通常,它已经存在真正的价值,在这种情况下,只需将false替换为true,你就可以了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.