How to get current page slug and post slug

get current page slug

$current_page = sanitize_post( $GLOBALS['wp_the_query']->get_queried_object() );
$current_slug = $current_page->post_name;

get current post slug

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

if you want to compare current page and post slug

if($current_slug == $post_slug){
	echo 'Active';
}

Leave a Reply

Your email address will not be published.