I want to Retrieve the Current Pagename , Inside my Breadcrumb , i tried many ways to get the idea work , but unfortunately they didn't work e.g :

           <?php wp_title('true'); ?>

           $pagename = get_query_var('pagename');
                if ( !$pagename && $id > 0 ) {
                // If a static page is set as the front page, $pagename will not be set. Retrieve it from the queried object
                $post = $wp_query->get_queried_object();
                $pagename = $post->post_name;
                }$slug = basename(get_query_var('pagename'));

for more Clearly Question , My Idea is to get the pagrname for the breadcrumb bootstrap , i mean lik this ' Home / PageName / Postname(if it navigated) .

1 Answer 1


Assuming you're doing this from inside the Loop, you can get it this way:

global $post;
$page_slug = $post->post_name;

Then just use echo $page_slug; in the location(s) you which to have it displayed.

For outside the loop, you will need to use different code:

$the_page = sanitize_post( $GLOBALS['wp_the_query']->get_queried_object() );
$slug = $the_page->post_name;
  • yeah i wanted it outside the loop . Thakns anyway man Jan 14, 2018 at 19:56
  • Ok. Give me a second and I'll update with that code.
    – Cedon
    Jan 14, 2018 at 21:29
  • Code has been added.
    – Cedon
    Jan 14, 2018 at 22:31
  • thanks for your Help , but the problem is when i enter to a specific post , it return to give the post name , not the page name . actually i wanted it to be like this : Home / " here the code you added for Me " like PageName / "here the post name . Jan 15, 2018 at 16:02
  • Page Name and Post Name are the same thing.
    – Cedon
    Jan 15, 2018 at 22:17

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.