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’.
- – 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.
If you are using the URL or Slug fields in this example, you would use the below code tag:-
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.
24 thoughts on “How to Dynamically Add a WordPress Post Title in Contact Form 7”
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.
Glad it helped! Sometimes the documentation can be a bit brief and confusing but we glad we helped!
Thanks. It saved my day.
Welcome : )
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.
Could you not add the
[dynamictext dynamictext-title]shortcode to display that?
But how to add custom subject, instead of page_title?
Hi David, how do you mean? You can set the subject to be whatever you like, and include the shortcodes within them as you wish.
when i add those shortcodes it shows whitespaces occupied, but the titles are not getting displayed
Are you referring to the form or the email?
If you are referring to the form then you should use
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.
Yes, it is possible, you would have to add the popup within the WooCommerce template files, it’s best practice to create a /woocommerce/ folder in your Child Theme if you are making changes to the core files. If you need some help with this, I’m happy to help ( :
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?
Do you mean as a placeholder or as pre-text?
Okay, I had a little play around with it, you could achieve that by adding the following code to your
This will create a shortcode you can use in CF7, then to display this shortcode you can add this within the form:
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” ]
I think I am looking for a placeholder for the text area.
Sorry about the late reply, honestly, I’d say it is easier handling this in jQuery, to be honest. It can be done using a CF7 hook but this would work for you…
Note, you will have to check the class of the Title of that page, so the element might need updating here…
Secondly, the text replacement would affect all CF7 forms on the site, so you may want to add the ID of the form if you only want it to change on a particular form.
Hope that helps buddy!
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
Thanks. Very useful. But can I get post-url instead of post-title or page-url?
You can indeed like so;
There is a full list of shortcodes you can use in their full documentation; https://sevenspark.com/docs/contact-form-7-dynamic-text-extension/shortcodes/included
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