Helping you build a better website
(and other interesting web stuff)

CSSHTMLJavaScriptjQueryMSSQLMySQLPHPSilvaTechnologiesWordpress
Silva Web Designs - Blog

How to Dynamically Add a WordPress Post Title in Contact Form 7

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. I hope this helps.

It’s good to share

Join the discussion