Skip to content

Instantly share code, notes, and snippets.

@apintocr
Last active December 10, 2019 15:58
Show Gist options
  • Save apintocr/1e568ca25ebcabae64a408d6c40cec62 to your computer and use it in GitHub Desktop.
Save apintocr/1e568ca25ebcabae64a408d6c40cec62 to your computer and use it in GitHub Desktop.
Edit Subject on Divi Contact Form (using add_filter)
<?php
/**
* Edit Subject on Divi Contact Form (using add_filter)
*
* Divi contact form does not allow you to change the subject from the interface.
* The problem is that on clients like Gmail the messages get threaded/organized under the same item/title.
* To solve this we need a unique subject for each new contact.
* However, Divi contact module does not have many hooks or filters, only allowing us to change the $headers[]
* This would be great if the 'Subject:' was set on that variable, it is not, so we need to ADD a extra 'Subject:'
* not an ideal solution, but it works and currently it is the only way to do this without editing the theme files.
*
* Just add this code to your child-theme functions.php and you are set to go.
* You can add extra variable like get_option('blogname') if you want.
*
* @author António Pinto <apinto@vanguardly.com>
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
add_filter('et_contact_page_headers', 'edit_divi_contact_form_subject', 10, 3);
function edit_divi_contact_form_subject($headers, $contact_name, $contact_email)
{
$headers[] = 'Subject: New contact from the website ' . ' (' . $contact_email . ')';
return $headers;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment