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.
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
Insert a new Field and set the following options:
Go to Advanced Tab β Custom CSS β Free Form CSS
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.Edit the Message Pattern and make sure the field is included by using %%dt-custom-title%%
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: