This shortcode returns the value of a specified value of the current WordPress page. This shortcode can be used across multiple types of WordPress templates and is not specific to posts. This shortcode includes a key attribute where you specify which variable you want to output.
[CF7_get_current_var key="<insert key>"]
This shortcode, because it is built to be flexible for any WordPress template, acts as an alias for some of the other functions like CF7_URL, CF7_get_post_var, CF7_get_custom_field, CF7_get_taxonomy, and CF7_get_attachment, therefore you can use those attributes when using the appropriate keys that act as their alias.
Example
If I wanted to get the title of the current page for a form that will be displayed in the site’s footer, the value of my dynamic field would use this:
CF7_get_current_var key='title'
And then the dynamic text form tag would look like this:
[dynamictext inputname "CF7_get_current_var key='title'"]
Possible Options
Any property that is available from the queried object (types: WP_Post, WP_User, and WP_Term), and returns a string or numeric value can be used such as:
- URL:
CF7_get_current_var key='url'- An alias for CF7_URL
- Title:
CF7_get_current_var key='title' - Slug:
CF7_get_current_var key='slug' - WordPress ID:
CF7_get_current_var key='ID'- On single posts, pages, and custom post types, the
post_idis returned—an alias for CF7_get_post_var key=’ID’ - On taxonomy archive pages, the
term_idis returned - On author pages, the user ID is returned
- May be empty, e.g. search results and 404 pages
- On single posts, pages, and custom post types, the
- Featured Image:
CF7_get_current_var key='image'- Returns the absolute URL of the featured image assigned to the current page or post—an alias for CF7_get_attachment
- Returns the absolute URL of the user’s avatar for author pages
- Categories/Tags/Custom Taxonomy:
CF7_get_current_var key='terms'- An alias for CF7_get_taxonomy
- Meta Data / Custom Fields:
CF7_get_current_var key='<meta key>'- On single posts, pages, and custom post types, this is an alias for CF7_get_custom_field
- Advanced Custom Fields ID:
CF7_get_current_var key='acf_id'- Used for returning values compatible with the
get_field()functions of ACF - On single posts, pages, and custom post types, the
post_idis returned—an alias for CF7_get_post_var key=’ID’ - On taxonomy archive pages, the
term_idis returned prefixed with the taxonomy, e.g.,category_123 - On author pages, the user ID is returned prefixed with
user_, e.g.,user_123 - May be empty for pages like search results and 404 pages
- Used for returning values compatible with the
Cache Compatibility
If cache compatibility mode is enabled for the form tag that uses this built-in shortcode, it does not make an AJAX request. Instead, it simply uses the preexisting value because page-specific values are safe to cache.
The only exception is when using CF7_get_current_var key='url' because that is an alias for CF7_URL, but it is also retrieved via JavaScript and does not send an AJAX request.
Demo
Check out the demo form below in how I’m using [dynamictext dynamictext-1 "CF7_get_current_var key='title'"] and [dynamictext dynamictext-2 "CF7_get_current_var key='slug'"] as my form fields:
View Source Code
This shortcode was added to the Contact Form 7 – Dynamic Text Extension WordPress plugin in version 3.4.0. View the current source code for the server-side shortcode or for the client-side JavaScript function.