【问题标题】:How to programmatically change the default messages in Contact Form 7?如何以编程方式更改联系表 7 中的默认消息?
【发布时间】:2020-04-03 17:49:10
【问题描述】:

我正在尝试在 WordPress 的 contact-form-7 插件中编辑垃圾邮件的错误消息。到目前为止,它只显示一条简单的消息,“尝试发送您的消息时出错”,我想更改它。但我不知道在代码中哪里可以找到发送此消息的位置。我找到了默认消息,但是一旦更改,这将无济于事。 我在哪里可以找到这个?

【问题讨论】:

  • 您看到管理面板中的设置了吗? wp-admin=>contact=>edit your form=>'here you can see "message" tab'
  • @Dhruv 是的,但我想在消息中包含一些变量,这是通过 wp admin 无法实现的

标签: wordpress contact-form-7


【解决方案1】:

有两种方法可以更改 CF7 中的默认消息,一种是使用具有选项卡“消息”的 admin cf7 表单编辑器,而第二种方法是挂钩插件触发的“wpcf7_messages”过滤器一次所有消息已设置,

//give a prioity >10 to ensure you filter hooks after those of the plugin.
add_filter('wpcf7_messages', 'change_spam_filter', 20,1);
function change_spam_filter($msgs){
  $msgs['spam']['default'] = "this is a custom spam message";
  return $msgs;
}

此过滤器仅在管理后端而非前端触发。如果需要在表单提交时过滤消息可以hook,

add_filter('wpcf7_display_message','',10,2);
function filter_spam_msg($message, $status){
  if('spam' != $status) return $message;
  $message = "this is a custom spam message";
  return $message;
}

编辑:请注意,从 CF7 插件的 v5.5 开始,HTML 格式的响应可以再在表单提交时显示。为此,您需要安装扩展程序。看到这个answer

【讨论】:

  • 我会试试看的!
  • 成功了吗?请注意,当前版本的 CF7 插件不再接受 HTML 格式的响应。为此,您需要使用插件。看到这个answer
猜你喜欢
  • 2020-05-09
  • 2011-11-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多