WordPress – How Can I Get Current Page Slug

Is there a way to get current page’s slug outside the loop?

if you know the page id, try following

$post_id = 1;
$post = get_post($post_id);
$slug = $post->post_name;

if you dont know the page id, try following

global $post;
$slug = get_post( $post )->post_name;
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments