This content explains how to easily add a title to a Contact Form 7. First, a form tag needs to be added to the functions.php file of the theme. Then, the title can be added to the form content using a shortcode. Finally, the title can be included in the email content using another shortcode. By following these steps, users can efficiently add a title to their Contact Form 7.
Are you wondering how to pass the article title to the Contact Form 7 simply and clearly? Let’s dive into the details with Minh Duy Solutions.
1. Add a form tag for Contact Form 7
To begin, copy the code snippet below and insert it into the functions.php file of your theme:
function custom_add_form_tag_mdsco_title() {
wpcf7_add_form_tag( 'mdsco_title', 'mdsco_title_form_tag_handler' );
}
add_action( 'wpcf7_init', 'custom_add_form_tag_mdsco_title' );
function mdsco_title_form_tag_handler( $tag ) {
return '<input class="wpcf7-form-control wpcf7-text hidden" aria-inval type="text" name="mdsco_title" value="'.get_the_title().'">';
}
2. Add the title to the form content
Next, paste the following shortcode into the content of your form:
[mdsco_title]
3. Include in the email content
To display the article title in the email content, use the following shortcode:
[mdsco_title]
This straightforward approach allows for seamless integration of article titles into Contact Form 7.