codingtcher.com
Theme Night
Home
Login

Wordpress get current category slug

Home » Tutorial Post » Wordpress get current category slug
// wordpress get current category slug
$category = get_category(get_query_var('cat'));
echo $category->slug; 
// Echo the category slug of default taxonomy (Category)

// wordpress get page slug
// Get the queried object and sanitize it
$current_page = sanitize_post( $GLOBALS['wp_the_query']->get_queried_object() );
// Get the page slug
$slug = $current_page->post_name;
echo $slug

Related Post