How to programmatically change the default messages in Contact Form 7?

ぃ、小莉子 提交于 2020-07-08 03:49:51

问题


I am trying to edit the error message for spam in the contact-form-7 plugin in WordPress. As of now it only shows a simple message with 'there was an error trying to send your message', I would like to change this. But I can not figure out where to find the place in the code where this message is sent from. I have found the default message, but once this is changed, this does not do anything. Where can I find this?


回答1:


There are 2 ways to change the default messages in CF7, one is using the admin cf7 form editor which has a tab 'Messages', while the 2nd way is to hook the 'wpcf7_messages' filter fired by the plugin once all the messages have been set,

//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;
}

this filter only fires on the admin back-end and not on the front-end. If you need to filter the message when the form is submitted you can 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;
}


来源:https://stackoverflow.com/questions/59268969/how-to-programmatically-change-the-default-messages-in-contact-form-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!