How to use the contact_form_message hook in Jetpack

The Jetpack Contact Form gives us a hook to filter what gets sent via email after a successful form submission but the documentation is not very helpful as it doesn’t provide an example. To top that the Comments are closed for the article. For details refer to the Jetpack Contact Form Message Hook page.

Copy the code below into a child theme’s functions.php file or a functionality plugin to append the value of $new_text to the end of the email.

Please change the value of $new_text to whatever you like.

Use Cases: You could use this hook to create a link to internal documentation or company policy.

Note: You need to check the email of the WordPress administrator, not the person sending the email, to notice the change.

<?php
function dd_change_successful_contact_form_submission_email_message($text){
$new_text = '<p>Text to add after email message. <a href="https://example.com/" target="_blank">Visit Example.com!</a></p>';
$text = $text . $new_text;
return $text;
}
add_filter ('contact_form_message', 'dd_change_successful_contact_form_submission_email_message');

Please share this post if it was of use to you.