Skip to content

Everything for WordPress, web development — and beyond

🚀 How to dynamically insert the page title into the Contact Form 7 email subject

🚀 How to dynamically insert the page title into the Contact Form 7 email subject

Your site has a dozen pages with a contact form, and every email arrives with the same subject line "Message from site." Which section did the visitor write from? Which services page? You end up guessing from the message text.

Contact Form 7 is the standard for WordPress forms with over 10 million active installations. But out of the box it cannot tell which page a form was submitted from. The email subject and body must be configured statically, so a single form used across multiple pages produces identical messages.

The Dynamic Text Extension (DTX) plugin solves this in five minutes without a single line of PHP. You add a hidden field to the form, and it automatically captures the page title, URL, or slug. Then you output that variable in the email subject or body via the template. Below is a step-by-step setup guide from scratch.

💡 Quick overview:

  • Install DTX from the WordPress.org directory and activate it alongside Contact Form 7
  • Add a hidden [dynamichidden] tag with the CF7_get_post_var shortcode to your form
  • Insert the variable into the email subject or body via the "Mail" tab
  • Test by submitting from two different pages; emails arrive with different subjects
  • If needed, add the page URL or GET parameters using the same mechanism

Step 1: Installing Dynamic Text Extension

Contact Form 7 Dynamic Text Extension plugin page in the WordPress.org directory

First, the plugin itself. It is free and available in the WordPress.org directory under the name Contact Form 7, Dynamic Text Extension.

Installation is standard: Plugins → Add New → search for "Dynamic Text Extension" → Install → Activate. You should already have Contact Form 7 active since DTX extends it specifically; without CF7 it serves no purpose.

Note that the plugin is actively maintained. As of June 2026 it has 100,000+ active installations, a 4.5 rating on WordPress.org, and compatibility with the latest WordPress version. The author, Chris Mav, also develops UberMenu. This is not one of those plugins abandoned after the first release.

Step 2: Adding a hidden field to the form

Now for the configuration inside Contact Form 7. Open the form you want to edit: Contact → Contact Forms → click the form name. You are on the Form tab.

Copy this code and paste it into the form body after your main fields but before the submit button:

1[dynamichidden page-title "CF7_get_post_var key='title'"]

Here is what happens. dynamichidden is a DTX field type: invisible to the visitor but included in the submission. page-title is the internal variable name (arbitrary but meaningful). Inside the quotes, the shortcode CF7_get_post_var key='title' pulls the current WordPress page title via the global $post object.

If you need the page URL instead of the title, replace the inner shortcode with CF7_URL:

1[dynamichidden page-url "CF7_URL"]

For the slug, use CF7_get_post_var key='slug':

1[dynamichidden page-slug "CF7_get_post_var key='slug'"]

You can add all three fields at once, and then you will see the title, URL, and slug in the email. Click Save below the form editor.

Step 3: Outputting the variable in the email template

The final step is telling Contact Form 7 where to insert the collected data. Go to the Mail tab inside the form.

In the Subject field, add the variable name in square brackets:

1[page-title]

The full subject might look like this: Message: [page-title]. Or if you added the URL: Inquiry from page: [page-url].

The same approach works in the Message Body field. You can insert the [page-title] variable anywhere in the template, before or after the main message text:

1Submission page: [page-title]
2URL: [page-url]
3
4Message:
5[your-message]

The variables page-title, page-url, and page-slug are the exact names you assigned in the [dynamichidden] tags in the previous step. They must match exactly.

Save the form and test: open any two pages on your site that contain this form and send a test message from each. The emails will arrive with different subjects depending on the title of the page where the visitor was.

Using GET parameters

DTX can read parameters from the URL, which is useful when passing additional information via a link. For example, an "Order consultation" button on a pricing page might link to /contact/?plan=pro. The shortcode for this:

1[dynamichidden selected-plan "CF7_GET key='plan'"]

In the email template, use [selected-plan]. The form will automatically insert the value pro from the query string.

The same technique works for UTM tags, campaign identifiers, and any other parameters you pass in the URL.

In this video, plugin author Chris Mav demonstrates basic DTX setup in three minutes, from installation to the first dynamic field. If any of the steps above raise questions, watch it: all actions are shown on screen in real time.

What to do when the form appears on all pages but you need different titles

The basic scenario described above covers the vast majority of cases: one form, page title in the email subject. But what if you have dozens of pages, each with its own form and unique set of fields? Creating and configuring DTX manually for each one takes time.

Here are three scenarios in order of increasing complexity:

  • One form on all pages. The ideal case for DTX: add the hidden field once, and the email subject picks up [page-title]. Setup takes five minutes.

  • Several different forms. Configure DTX in each form separately, but copy the tags between forms via the clipboard. The hidden field with CF7_get_post_var works the same way in all forms.

  • Dozens of pages + A/B tests. If you need not just to distinguish pages but to track form conversions, consider Gravity Forms or WPForms. They have built-in submission analytics and conditional notification routing. DTX is not a competitor here; it solves a specific task (dynamic fields) and solves it for free.

⁉️🤔 Frequently asked questions

Does DTX work with the latest WordPress version?

Yes, the plugin is compatible with WordPress 6.7+ and receives regular updates. As of June 2026 the author releases updates every 1-2 months, with the most recent in May 2026. Check the version on the plugin page, where current compatibility is always listed.

Can I insert the title of a specific page rather than the current one?

CF7_get_post_var pulls data from the global $post object, which refers to the page where the form is displayed. To insert the title of a different page, specify its ID: CF7_get_post_var key='title' post_id='42'. You can find the page ID in the admin: Pages → All Pages → hover over the title, and the ID appears in the URL.

What if the variable is not appearing in the email?

Check three things. First: do the names match? The attribute value in [dynamichidden name ...] and the variable [name] in the template must be identical, including case. Second: is the CF7 shortcode wrapped in different quote types? Inside double quotes, DTX attributes must use single quotes ("CF7_get_post_var key='title'"). Third: is Contact Form 7 itself active? Without it, DTX does not work.

Why use a hidden field when I could just type the title in the subject?

The hidden field automates the process. If you have one form on ten pages, without DTX you would need to create ten form copies with different subjects or manually change the subject for each page. DTX does this for you: add the hidden field once, and the email subject always matches the submission page.

Can I use DTX to pre-fill visible fields?

Yes, replace dynamichidden with dynamictext or dynamicemail. For example, [dynamictext user-name "CF7_get_current_user key='user_nicename'"] will pre-fill the field with the logged-in user's name. The visitor will see the pre-filled value and can edit it before submitting.

Does the plugin conflict with caching?

No. DTX inserts values server-side when the page renders, so cache plugins like WP Rocket do not affect it. If you use server-level caching (Varnish, Nginx FastCGI), make sure pages with forms are excluded from the cache; otherwise, the title may "stick" to the first visitor.

Start with the first scenario: install DTX, add a hidden field to your current form, and test emails from two different pages. Nine out of ten sites stop here because the need for more complex logic simply never arises.