I am trying for hours and I managed to get full slug for parent of sub-page when I am on 3rd level sub-page I can not get slug of the top parent page. Example domain.com/top_page/sub_page/sub_sub_page

I need to get full slug 'top_page/sub_page/sub_sub_page'

I am doing this for language sites that are on sub-domains (individuals sites). These pages have same slug across sub-domains. So I want to link language site that when you are on some given page link to language site will take you to that page in that language (not home page of that language).

example of hyperlink to English language sub-domain:

echo '<a href="en.domain.com/'.get_FULL_SLUG).'">'English'</a>';

Is it possible to get slug of top parent when you are on third level page, sub-sub-page

Hope somebody can help

2 Answers 2


This would replace domain.com/top_page/sub_page/sub_sub_page with /top_page/sub_page/sub_sub_page

$path = str_replace(home_url(),'',get_permalink());
  • If I understand...you are suggesting to take current permalink and get full slug from there exclude current sub-domain from permalink and after create dynamic link on language flags. Short example on how it would be of great help...Thanks again!
    – a.shaki
    Commented Apr 2, 2012 at 11:37
  • If your home url for the english site is en.domain.com/ then removing the home_url, and then adding in say fr.domain.com to the start of the permalink, you'd have the new URL. Eitherway your question is not about 'full slugs' as that would be 'sub_sub_page' which isn't what you stated you want. This question is about permalinks.
    – Tom J Nowell
    Commented Apr 2, 2012 at 12:02
  • I guess you are right...there are two questions: how to get full slug of the current page and how to replace domain so flags will link to related pages...Example: Contact page when you click on any language flag it would take you to contact page in that language, I will make sure that contact pages in all languages have same slug...Not sure which way would be the best to achieve it.
    – a.shaki
    Commented Apr 3, 2012 at 7:45
  • I've already answered that though, for en.domain.com/contact $path == '/contact', so your french link is "fr.domain.com".$path, your german "de.domain.com".$path etc etc etc
    – Tom J Nowell
    Commented Apr 3, 2012 at 9:59
  • 1
    Actually this has worked...thank you Tom. For other users this is what I have done: 1. insert in header.php following <?php $full_slug = str_replace(home_url(),'',get_permalink()); ?> 2. Linked language flags using following code: <?php Echo "<a href=pt.domain.com$full_slug>" ?><img src="<?php bloginfo('template_url'); ?>/assets/images/flags/pt.jpg" alt="" />Português</a>
    – a.shaki
    Commented Apr 3, 2012 at 11:34

Directly using get_page_uri:

$path = get_page_uri($post_or_id);

Result is e.g. top-level-page/sub-page/current-page. This function is used internally by get_page_link etc.

  • To get the current page you can pass null as parameter. echo "Full slug: ", get_page_uri(null);
    – Fred
    Commented Nov 21, 2014 at 15:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.