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

DTX Shortcode: Current URL

This shortcode included in Contact Form – Dynamic Text Extension returns the current URL of the page the form is on.

[CF7_URL]

This shortcode also includes an optional part attribute where you can choose to get just the scheme (aka protocol e.g., “http” or “https”), host (i.e. the domain name), port (may return blank if using port 80), path, query, or fragment.

Examples

To get just the full, absolute URL, the value of my dynamic field would use this:

CF7_URL

And then the dynamic text form tag would look like this:

[dynamictext inputname "CF7_URL"]

Examples for getting the parts look like these:

[dynamictext inputname "CF7_URL part='host'"]
[dynamictext inputname "CF7_URL part='port'"]
[dynamictext inputname "CF7_URL part='path'"]
[dynamictext inputname "CF7_URL part='query'"]
[dynamictext inputname dtx_pageload "CF7_URL part='fragment'"]

Getting the fragment (also known as “hash” or “anchor” in the URL) is only available when cache compatibility is enabled since the fragment is not sent to the server.

Cache Compatibility

If the HTML of your webpage is being cached, preventing the server from processing the shortcode before displaying the form, then you can enable cache compatibility mode for this form tag.

However, this built-in shortcode is unique in that it does not make an AJAX request. Instead, it simply uses JavaScript to pull the current URL or a part of it.

Demo

Check out these fields in action!

    My website uses an SSL certificate!

    Mine is empty since it uses port 80

    If this is blank, click this link to reload the page with an anchor link in the URL!

    View Source Code

    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) ""
    }