如何在联系表7中删除跨接包装? [英] How can I remove the span wrapper in Contact Form 7?

查看:62
本文介绍了如何在联系表7中删除跨接包装?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 WordPress 主题中使用联系表7

当前返回 span input

<span class="wpcf7-form-control-wrap name">
  <input type="text" name="name" class="wpcf7-form-control wpcf7-text wpcf7-validates-as-required form-control" id="name">
</span>

但是我只需要输入

<input type="text" name="name" class="wpcf7-form-control wpcf7-text wpcf7-validates-as-required form-control" id="name">

如何删除 span 包装器?

推荐答案

我遇到了同样的问题,最后使用 wpcf7_form_elements 结束了过滤器以使用正则表达式删除< span> 标记。例如,您可以将此代码复制粘贴到您的 functions.php 文件中。在这里,我通过一个匿名函数作为回调,因此请确保PHP> = 5.3。

I faced the same problem and finally ending by using the wpcf7_form_elements filter to remove the <span> tag with a regex. You can for example copy-paste this code in your functions.phpfile. Here I pass an an anonymous function as a callback, so be sure to have PHP >= 5.3.

add_filter('wpcf7_form_elements', function($content) {
    $content = preg_replace('/<(span).*?class="\s*(?:.*\s)?wpcf7-form-control-wrap(?:\s[^"]+)?\s*"[^\>]*>(.*)<\/\1>/i', '\2', $content);

    return $content;
});

这篇关于如何在联系表7中删除跨接包装?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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