The Contact Form 7 WordPress plugin is a very powerful plugin that is very typically used on a lot of WordPress websites that requires forms. There are times we run into situations where we need to dynamically add a WordPress post title, URL or fields in either the subject line or email body generated by the form. Luckily, this situation is very easy to handle with the help of an extension plugin. In this tutorial, we will teach you how to dynamically add a WordPress post title in the Contact Form 7 plugin.
Step 1: Install the Contact Form 7 Dynamic Text Extension Plugin
First things first, we need to download and install the ‘Contact Form 7 Dynamic Text Extension Plugin’ from the WordPress plugin directory. This plugin will allow the ability to add dynamic content capabilities to the ‘Contact Form 7 Plugin’.
Please Note:
- – Make sure that you also have the ‘Contact Form 7 Plugin’ installed.
- – This is a very powerful plugin and dynamically adding the WordPress post title is just one of its many capabilities.
Step 2: Generate the Hidden Dynamic Content Tag in Contact Form 7
Now we will generate the hidden dynamic content tag that will be used to dynamically add the WordPress post title in ‘Contact Form 7’.
While in the WordPress Dashboard, go to the ‘Contact Form 7’ settings page and make sure you are viewing the ‘Form’ tab. Copy and paste the form-tag code below then add it inside the form code block:-
[dynamichidden page-title "CF7_get_post_var key='title'"]
The above code will add a hidden text input to the form which will pre-populate the page title. This is good to use when you are using the same contact form on multiple pages so you know where the user has submitted the form from.
Alternatively, you can display the page URL or slug using one of the below shortcodes instead:-
[dynamichidden page-url "CF7_bloginfo show='url'"]
[dynamichidden page-slug "CF7_bloginfo show='url'"]
Step 3: Displaying the Hidden Dynamic Content Tag Variable in Contact Form 7
Finally, we will display the hidden dynamic content tag variable in ‘Contact Form 7’ form.
While still on the ‘Contact Form 7’ settings page, click on the ‘Email’ tab. You can now use the variable code tag below to display the WordPress post title in either the ‘Subject’ or ‘Message Body’ of the ‘Contact Form 7’ form.
[page-title]
If you are using the URL or Slug fields in this example, you would use the below code tag:-
[page-url]
[page-slug]
If you are having problems getting this tutorial to work please reread the tutorial and try again, if you still cannot get it to work please leave us a comment below and we will respond as soon as possible. We hope this helps.
Thank you so much. I spent a lot of time researching this problem and you are the first one to explain it in a way that actually works! Have a nice day.
Thanks. It saved my day.
Is there a way for the user to actually see the the title of the post in the form they are completing? For example, the dynamic title would show at the top of the form that the user is completing.
But how to add custom subject, instead of page_title?
when i add those shortcodes it shows whitespaces occupied, but the titles are not getting displayed
Referring to the email,
It takes the space but it is not showing the title.
Hi, i have embed a contact form in a popup after clicking a button, inside a product, but i can’t populate either to post (product) title or the link.
Is that possible?
Thanks in advance.
Hi,
I have a text box in my form where I want to display the page title.
example Hello, I am interested in “then page title should show”
How would I be able to do this?
Hi, Nathan,
Thank you for the help,
How do I get this to display inside the text area field?
Hi Nathan please see below the code I am using.
[textarea* Message id:Message class:Message placeholder “Hello, I am interested in then the Page title should be here” ]
Hi Nathan
I think I am looking for a placeholder for the text area.
kind Regards
Hi,
Nathan,
please see the error I get below.
Your PHP code changes were rolled back due to an error on line 633 of file wp-content/themes/houzez/functions.php. Please fix and try saving again.
syntax error, unexpected ‘var’ (T_VAR), expecting end of file
Hi,
Thanks. Very useful. But can I get post-url instead of post-title or page-url?
Hello, I need help! I have a Tours Website and different Packages offering as posts. In every post i have a Enquiry button which leads them to the enquiry page. But problem is, i want to show the Product name in the email received when user filled that form, CF7 provides the special mail tags for the current page or post title(means where the form is present) but i want to show that previous page or post title means product title name from which client is redirected to contact form page. Is there any way to solve this?? Please help
Great. I got a good idea. Thank you for sharing.
I tried this
[dynamichidden page-title “CF7_get_post_var key=’title'”]
and it didn’t work