Amit

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';
}

Last Update on:March 5th, 2023 at 5:19 pm


How to Send an Email on ACF Form Submission
Previous post