WordPress Tip: Find the Current Page Slug
Aug 9th, 2007 by Michael
While I was working on a WordPress template today, I needed to find the current page’s post_slug. After investigating the function is_single in wp-includes/query.php, I discovered the following method for determining the current page ID, post title, or post name:
$post_obj = $wp_query->get_queried_object();
$post_ID = $post_obj->ID;
$post_title = $post_obj->post_title;
$post_name = $post_obj->post_name;

[…] keep forgetting this - good thing i stumbled on this tip on finding the current page slug when you are buliding a wordpress […]
So, after all, what is variable the page slug? is it the post_name?
Hi,
is this still the only way to get the page slug/title before The Loop?
I’m on version 3.3.3.
Hi, Michael!
Thanks for the tip. It helped me a lot!
[]’s