wordpress 联系表 7 自动添加 p 标签
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32539905/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Contact Form 7 auto added p tags
提问by Nenad Vracar
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. 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.
问题是它几乎在每个元素之后添加了随机的 p 标签,而且第一个文本字段由于某种原因而略高于其他两个字段,而它们都应该是内联的。而且我认为这不是 css 问题,因为以前我在平面 HTML 中对此进行了编码,并且所有字段都是内联的,因此我认为它必须与联系表格 7 相关。
回答by rnevius
According to the Contact Form 7 Docs, you can disable "wpautop" for the plugin by placing the following constant in wp-config.php:
根据Contact Form 7 Docs,您可以通过在wp-config.php 中放置以下常量来禁用插件的“wpautop” :
define( 'WPCF7_AUTOP', false );
回答by skip405
If editing wp-config.php
is not the solution for you, there's a handy filter.
Put it in your functions.php
.
如果编辑wp-config.php
不是您的解决方案,这里有一个方便的过滤器。把它放在你的functions.php
.
add_filter('wpcf7_autop_or_not', '__return_false');
add_filter('wpcf7_autop_or_not', '__return_false');
回答by Hitesh Prajapati
I would like to say something about this, when we want reduce auto P tag form the we should go with below filter and just write blow code in function.php.
我想说一下,当我们想要减少自动 P 标签形式时,我们应该使用下面的过滤器,只需在 function.php 中编写代码。
add_filter('wpcf7_autop_or_not', '__return_false');
回答by silver
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短代码
e.g.
例如
[raw][contact-form-7 id="1" title="Contact Us"][/raw]
回答by Sagive SEO
I tried many answers but nothing workedso...
I ended up using simple CSS to specifically target empty P tags
in the form itself like this:
我尝试了很多答案,但没有任何效果......
我最终使用简单的 CSS 专门针对
表单本身中的空 P 标签,如下所示:
.wpcf7-form p:empty { display: none; }
This worked for me and, its a simple solution.
这对我有用,而且是一个简单的解决方案。