Custom Contact Form 7 Special Mail Tags

Contact Form 7 is the least difficult, free and primarily employed plugin for generating forms in WordPress. It is also hugely customizable. We can send out e-mail in a tailored method or structure. Most of the moments we use the sort fields to reflect in the mail. So considerably this is quickly doable.

But have you at any time thought about exhibiting any other possible info in the mail? Enable’ say, you want to clearly show the IP address the place the contact details had been despatched from.

Effectively, this is currently accessible with Contact Form 7 and that is one particular of the Specific Mail Tags. Right here the tag we will be applying is [_remote_ip]. You can have a total record of existing exclusive tags here.

But we will not end here fairly we will go one particular phase further. Enable’ say is there any likelihood of owning extra these kinds of tags? The good information is Yes. Contact Form 7 supplies hook for this and we can use that. Enable’ have a functionality here for applying website url as a exclusive tag.

// Hook for added exclusive mail tag
incorporate_filter( 'wpcf7_exclusive_mail_tags', 'wti_exclusive_mail_tag', 20, 3 )

/** 
 * Specific mail tag for website url
 * 
 * @param string
 * @param string
 * @param string
 * 
 * @return string
 */
perform wti_exclusive_mail_tag( $output, $name, $html )

// For backwards compatibility
$name = preg_replace( '/^wpcf7./', '_', $name )

if ( '_website_url' == $name ) 
// Get the website url
$web site_url = get_alternative( 'siteurl' )
          
                // Create clickable backlink
                $output = make_clickable( $web site_url )


return $output

To use this in the mail template, you need to place [_site_url]. I have outlined only one particular tag, you can incorporate as many here dependent on conditions. Place the above code in a plugin or in the features.php file of the active topic. That’ it. Content Coding.

Leave a Reply

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