Tag Archives: the_loop

WordPress Get the current post slug

Hi there, I have search the net and this person found a way to get the slug the easier way.

 

The common approach:

$post_obj = $wp_query->get_queried_object();
$post_ID = $post_obj->ID;
$post_title = $post_obj->post_title;
$post_slug = $post_obj->post_name;

His approach:

$slug = basename(get_permalink());

That's it. Just include it inside the_loop.
Source: http://www.joshstauffer.com/get-post-slug-in-wordpress/