MyListing Club

Replace MyListing's Contact Form 7 With Elementor Pro

Building better MyListing websites. One code snippet at a time.

Overview

The Replace MyListing’s Contact Form 7 With Elementor Pro code snippet provides more customization options within a MyListing website and is part of the overall solution outlined in this guide.

Implementation

  1. Grab the code snippet.
  2. Follow the provided instructions.
  3. Save your changes.
				
					//// INSTRUCTIONS: 
//// Copy and paste the code snippet below into the child theme's functions.php file.
//// You can edit the functions.php file from your WordPress dashboard (Appearance > Theme Editor) or via FTP.

--------------------------- CODE SNIPPET IS BELOW THIS LINE --------------------------- 

// REPLACE MYLISTING'S CONTACT FORM 7 WITH ELEMENTOR PRO
// If the Contact Email field IS NOT filled in by the listing owner, the form will send to the listing owner.
// If the Contact Email field IS filled in, the form will send to the email addresses entered, rather than the listing owner.
function contact_form_email_func( $atts ){
	$postID = get_the_ID();
	$job_email = get_post_meta($postID, '_job_email')[0];
	if(!$job_email){
		$author_id = get_post_field ('post_author', $postID);
		$job_email = get_the_author_meta('user_email', $author_id);
	}
	return $job_email;
}
add_shortcode( 'contact-form-email', 'contact_form_email_func' );