Skip to content
Home » Documentation » Contact Form 7 – Dynamic Text Extension » Shortcodes » DTX Shortcode: Current Page Variables

DTX Shortcode: Current Page Variables

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'
  • 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_id is returned—an alias for CF7_get_post_var key=’ID’
    • On taxonomy archive pages, the term_id is returned
    • On author pages, the user ID is returned
    • May be empty, e.g. search results and 404 pages
  • 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'
  • Meta Data / Custom Fields: CF7_get_current_var key='<meta key>'
  • 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_id is returned—an alias for CF7_get_post_var key=’ID’
    • On taxonomy archive pages, the term_id is 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

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.

    Related Post Module Attributes Before

    array(29) {
      ["post_type"]=>
      string(4) "post"
      ["post_id"]=>
      string(1) "0"
      ["exclude"]=>
      string(1) "0"
      ["title"]=>
      string(32) "Related Articles & Tutorials"
      ["description"]=>
      string(0) ""
      ["max"]=>
      string(1) "3"
      ["post_ids"]=>
      string(0) ""
      ["exclude_ids"]=>
      string(0) ""
      ["is_series"]=>
      string(0) ""
      ["featured_term"]=>
      string(3) "307"
      ["exclude_terms"]=>
      string(0) ""
      ["exclusive"]=>
      string(1) "1"
      ["order"]=>
      string(4) "DESC"
      ["show_image"]=>
      string(2) "on"
      ["image_size"]=>
      string(6) "medium"
      ["menu_order_label"]=>
      string(0) ""
      ["show_order_label"]=>
      string(2) "on"
      ["show_date"]=>
      string(2) "on"
      ["show_meta_keys"]=>
      string(2) "on"
      ["show_modified"]=>
      string(0) ""
      ["show_author"]=>
      string(0) ""
      ["show_categories"]=>
      string(0) ""
      ["show_primary_category"]=>
      string(0) ""
      ["show_description"]=>
      string(0) ""
      ["show_reading_time"]=>
      string(2) "on"
      ["show_cta"]=>
      string(2) "on"
      ["cta"]=>
      string(9) "Read more"
      ["autoplay"]=>
      string(0) ""
      ["allow_sticky"]=>
      string(0) ""
    }
    

    Related Post Module Attributes

    array(29) {
      ["post_type"]=>
      string(4) "post"
      ["post_id"]=>
      string(1) "0"
      ["exclude"]=>
      string(1) "0"
      ["title"]=>
      string(32) "Related Articles & Tutorials"
      ["description"]=>
      string(0) ""
      ["max"]=>
      string(1) "3"
      ["post_ids"]=>
      string(0) ""
      ["exclude_ids"]=>
      string(0) ""
      ["is_series"]=>
      string(0) ""
      ["featured_term"]=>
      string(3) "307"
      ["exclude_terms"]=>
      string(0) ""
      ["exclusive"]=>
      string(1) "1"
      ["order"]=>
      string(4) "DESC"
      ["show_image"]=>
      string(2) "on"
      ["image_size"]=>
      string(6) "medium"
      ["menu_order_label"]=>
      string(0) ""
      ["show_order_label"]=>
      string(2) "on"
      ["show_date"]=>
      string(2) "on"
      ["show_meta_keys"]=>
      string(2) "on"
      ["show_modified"]=>
      string(0) ""
      ["show_author"]=>
      string(0) ""
      ["show_categories"]=>
      string(0) ""
      ["show_primary_category"]=>
      string(0) ""
      ["show_description"]=>
      string(0) ""
      ["show_reading_time"]=>
      string(2) "on"
      ["show_cta"]=>
      string(2) "on"
      ["cta"]=>
      string(9) "Read more"
      ["autoplay"]=>
      string(0) ""
      ["allow_sticky"]=>
      string(0) ""
    }