Skip to main content
All CollectionsTroubleshooting and FAQsFrequently Asked QuestionsContact Form Module
How to Include the Post/Page's Title in the Contact Form's Email Body
How to Include the Post/Page's Title in the Contact Form's Email Body

Learn how to add the current post/page/product/etc title to the contact form email body.

Updated over 4 months ago

By default, there is no option to add Dynamic Content in a contact form field. Because of that, you cannot display the Post/Page's title from where a Contact Form module was submitted.

This article provides all the customization steps to implement the Post/Page's title in the Contact Form module's Email body.

  1. For each Contact Form module that you want to include the Post/Page's title in the Email's body, open its setting by clicking on the Gear icon

  2. Insert a new Field and set the following options:

    • Field ID: dt-custom-title

    • Title: Post Title

      Contact Form module  - Filed ID and Field Title

    • Type: Input Field

    • Required Field: No

      Contact Form module - Field Type and Requirement

  3. Go to Advanced Tab β†’ Custom CSS β†’ Free Form CSS

  4. Add this CSS code:

    selector {
    display: none;
    }


    The CSS code will hide the field from the front end since we don't actually need to display it.

    Contact Form module - Field's Advanced Tab β†’ Custom CSS β†’ Free Form CSS

  5. Edit the Message Pattern and make sure the field is included by using %%dt-custom-title%%

    Contact Form module - Message Pattern

  6. If you are using a Child theme, edit the functions.php file and place this PHP code after the existing code:

    // Add current post title to a contact form hidden field
    function add_post_title_to_cf_field(){
    // Get post title
    global $post;
    $title = get_the_title($post->ID); ?>

    <!-- Script for adding the retrieved title into the hidden field -->
    <script>
    (function($){
    $(document).ready(function(){
    if ($('p[data-id="dt-custom-title"] input').length) {
    $('p[data-id="dt-custom-title"] input').attr('value','<?php echo $title; ?>');
    }
    });
    })(jQuery);
    </script>
    <?php }
    add_action('wp_footer', 'add_post_title_to_cf_field');

Note: if you are not using a Child theme, you can install and activate the Code Snippets plugin. The above PHP code can be added as PHP Snippet.

The result can be seen in the screenshot below:

Contact Form module - Customization Result
Did this answer your question?