How To Move The Divi Contact Form Module To A Child Theme - kary4/divituts GitHub Wiki
If you want to add some custom features to your Contact Form module and you don't want to lose the changes when you update/reinstall then you need to use a child theme.
Firstly, you need to redefine the Contact Form module in the child theme and then you can add any changes to the Contact Form module. Here are the steps you need to follow to move the Contact Form module to a child theme.
-
Create a child theme or simply download it from here: https://github.com/kary4/divituts/wiki/divi-child-theme
-
In the child theme folder create a new folder, for example
includesfolder. -
Now copy the
divi/includes/builder/module/ContactForm.phpfile into thechild-theme/includes/folder. -
Rename the file to something else, for example:
custom-ContactForm.php. -
Open up the custom-ContactForm.php file and replace this code (the first line):
class ET_Builder_Module_Contact_Form extends ET_Builder_Module_Type_PostBased
with:
class custom_ET_Builder_Module_Contact_Form extends ET_Builder_Module_Type_PostBased
Next, find this line: $this->vb_support = 'on'; and replace it with $this->vb_support = 'off';.
Also, remove the following line at the very bottom:
new ET_Builder_Module_Contact_Form;
- Next step, add the following code to the functions.php file in your child theme folder:
/*================================================
#Load custom Contact Form Module
================================================*/
function divi_child_theme_setup() {
get_template_part( '/includes/custom-ContactForm' );
$cfm = new custom_ET_Builder_Module_Contact_Form();
remove_shortcode( 'et_pb_contact_form' );
add_shortcode( 'et_pb_contact_form', array( $cfm, '_shortcode_callback' ) );
}
add_action( 'et_builder_ready', 'divi_child_theme_setup' );
Now, if you want to modify the default subject field of the Contact Form search for the following code in the ContactForm.php in your child theme folder:
wp_mail( apply_filters( 'et_contact_page_email_to', $et_email_to ),
et_get_safe_localization( sprintf(
__( 'New Message From %1$s%2$s', 'et_builder' ),
sanitize_text_field( html_entity_decode( $et_site_name, ENT_QUOTES, 'UTF-8' ) ),
( '' !== $title ? sprintf( _x( ' - %s', 'contact form title separator', 'et_builder' ), $title ) : '' )
) ),
! empty( $email_message ) ? $email_message : ' ',
apply_filters( 'et_contact_page_headers', $headers, $contact_name, $contact_email )
);
and replace it with:
wp_mail( apply_filters( 'et_contact_page_email_to', $et_email_to ),
et_get_safe_localization( sprintf(
__( '%1$s has sent you a message %2$s', 'et_builder' ),
sanitize_text_field( html_entity_decode( $contact_name, ENT_QUOTES, 'UTF-8' ) ),
( '' !== $contact_email ? ' by ' . $contact_email : '' )
) ),
! empty( $email_message ) ? $email_message : ' ',
apply_filters( 'et_contact_page_headers', $headers, $contact_name, $contact_email )
);
That's it.