gwp_parent_slug
The gwp_parent_slug Merge Tag for Gravity Forms returns the slug of one of the parent posts of the current post and let’s you pick the depth of ancestor you need. It only returns a value if there is actually a parent post.
Slug of the direct parent post
{gwp_parent_slug}
Returns the slug of the direct parent post (first ancestor) of the current page. Default is depth=0, which return the direct parent. depth=’top’ returns the highest parent.
Example
Let’s say we have a post called ‘Me’. The parent of this post is ‘Mama’ (slug = mama). The parent of the post ‘Mama’ is ‘Grandma’ (slug = grandma) en the parent post of Grandma is ‘Great Grandma’ (slug = great-grandma).

So when we are reading the ‘Me’ article, the url looks like this:
https://gravitywp.com/great-grandma/grandma/mama/me/
Merge Tag | Output | Information |
---|---|---|
{gwp_parent_slug} or{gwp_parent_slug depth="0"} | mama | If you want the get the direct parent of the current post. |
{gwp_parent_slug depth="1"} | grandma | Get’s you the parent of your parent. |
{gwp_parent_slug depth="2"} | great-grandma | Get’s you the parent of the parent of your parent. |
{gwp_parent_slug depth="top"} | great-grandma | Get’s you the ‘oldest’ or better said ‘highest’ parent |
Or you can see it like this:
|
|
| |
great-grandma/ | grandma/ | mama/ | me/ |
| {gwp_parent_slug} |
What’s the difference with gwp_url?
The gwp_url will look at the full url and use that as basis for indexing which part of the url you want. So it doesn’t check if there is a parent post, it will just give you any part of the slug (also if that is a category page for example).
The gwp_parent_slug will look if there is actually a parent post (parent page) and give you the slug of this parent (or higher parent if you use the depth parameter).
This is very handy if you’re using the parent post slugs in your gvlogic shortcode of Gravity Forms conditional logic shortcode, since you can for example only show certain information if the page is a child of a certain parent.
For example:
[gvlogic if="{gwp_parent_slug}" is="mama"]Show this content when my current parent post slug is mama.[/gvlogic]
[gravityforms action="conditional" merge_tag="{gwp_parent_slug depth='top'}" condition="is" value="great-grandma"]Show this content when the highest parent post slug is great-grandma.[/gravityforms]
Frequently Asked Questions
The {gwp_parent_slug} merge tag returns the slug (URL-safe name) of the direct parent page or post of the page where the Gravity Form is embedded. It’s great for dynamically referencing a parent page in confirmation messages, HTML content blocks, or conditional logic. If the current page doesn’t have a parent, it returns nothing.
Example:{gwp_parent_slug}
You can use the depth parameter to specify which level of ancestor you want to return. The depth starts at 0 for the direct parent, 1 for the grandparent, and so on. You can also use depth=”top” to retrieve the top-level parent.
Example:{gwp_parent_slug depth="1"}
This will return the grandparent slug of the current page.
The value depth=”top” tells GravityWP to return the highest ancestor in the page hierarchy, regardless of how many levels deep the current page is. In contrast, numeric values like 1 or 2 return parents at a fixed distance.
Example:{gwp_parent_slug depth="top"}
This returns the oldest parent in the chain, like “company” if you’re on a sub-subpage.
Use gwp_parent_slug when you want to get the actual WordPress parent page/post, not just a URL segment. Unlike gwp_url, this tag ensures you’re working with hierarchical post relationships perfect for setting up conditional logic based on parent slugs.
Example conditional logic (using GravityViews gvlogic shortcode):[gvlogic if="{gwp_parent_slug}" is="hr-department"]
This is part of the HR Department section.
[/gvlogic]
Yes! To test it, create a form and embed it on a child page (e.g., a form under /company/hr-department/leave-request-form/). Then use an HTML field inside the form to output:<p>Direct parent: {gwp_parent_slug}</p>
<p>Grandparent: {gwp_parent_slug depth="1"}</p>
<p>Top-level: {gwp_parent_slug depth="top"}</p>
If the hierarchy is set correctly, you’ll see values like:
-hr-department
-company
-company
Last updated: 22-07-2025