Allow html in Contact Form 7 error messages

Contact Form 7 has a filter where one can alter the messages being sent back to the browser called wpcf7_validation_error.

A simple htmlspecialchars_decode altering the $message variable before returning will do the trick.

This function will run on any error for any form you have in your site (any CF7 form that is). If you want to only run it on specific forms the $args variable contains the name of the input field that is throwing the error. As long as your input field names are unique across forms you should be good using an if statement.

add_filter('wpcf7_validation_error', 'my_error_message_alter', 1, 2);
function my_error_message_alter($message, $args){
    //allow html in the error message
    $message = htmlspecialchars_decode($message);
    return $message;
}

2 responses to “Allow html in Contact Form 7 error messages

Leave a Reply

Your email address will not be published. Required fields are marked *