gwp_url
The gwp_url Merge Tag for Gravity Forms is able to return the WordPress site url, the WordPress home url, the current url, or an element of the current url.
The gwp_url merge tag has the following possible parameters:
Type parameter
The type parameter determines what url component to return. It has the following possible values:
- site_url: Returns the URL for the current site where WordPress application files are accessible.
- home_url: Retrieves the URL for the current site where the front end is accessible (basically what users need to type in their browser url to reach your site).
- scheme: Returns http or https.
- domain: Returns the full domain or a part of it if combined with the index parameter.
- path: Returns the full path after domain, or a part of it when combined with the index paramater.
Index parameter
The index parameter is an optional parameter to retrieve a part of the URL-path or domain. It must be an integer value. A positive value returns the element counted from the left, starting with 0. A negative value returns the element counted from the right.
How to use the gwp_url merge tag
{gwp_url type= index=}
Examples | Output |
---|---|
{gwp_url} | https://gravitywp.com/doc/gwp_url/ |
| https://gravitywp.com |
| https://gravitywp.com |
| https |
| gravitywp.com com gravitywp |
| /docs/gwp_url/ gwp_url docs |
Subdomain url
How does it work on a subdomain? Check it out.
Examples | Output |
---|---|
{gwp_url type=domain} | test.com |
{gwp_url type=domain index=-2} | ddev |
{gwp_url type=domain index=-1} | site |
{gwp_url type=domain index=0} | test |
{gwp_url type=domain index=1} | ddev |
{gwp_url type=domain index=2} | site |
Frequently Asked Questions
This merge tag lets you dynamically pull parts of the current page URL or the site’s configured URLs into your Gravity Forms. It’s useful for showing the full current URL, the domain name, the WordPress home or site URL, or specific URL segments.{gwp_url}
{gwp_url type="site_url"}
{gwp_url type="domain" index="0"}
site_url refers to where your WordPress core files are installed.
home_url refers to your site’s frontend address. In most cases, they’re the same but they may differ if WordPress is installed in a subdirectory.{gwp_url type="site_url"} → https://example.com/wordpress
{gwp_url type="home_url"} → https://example.com
Use the index parameter with type=”domain” or type=”path” to get a specific segment.
Positive numbers count from left (starting at 0).
Negative numbers count from the end.{gwp_url type="domain" index="0"} → subdomain (from sub.example.com)
{gwp_url type="domain" index="1"} → example
{gwp_url type="domain" index="2"} → com
{gwp_url type="path" index="0"} → first folder (e.g., “products”){gwp_url type="path" index="-1"} → last path (e.g., “item-a”)
Yes, {gwp_url} merge tags work inside Confirmation messages, Notifications, and HTML fields. Just make sure you’re not using it in a field that requires calculation or field logic it’s for displaying string/text values only.{gwp_url type="path" index="-1"} → Last part of the path (great for dynamic confirmation content!)
If the index is out of range (for example, requesting index 3 on a 2-part domain), {gwp_url} will return an empty string. No error will show, but nothing will be displayed.{gwp_url type="path" index="99"} → (returns nothing)
Last updated: 18-07-2025