Get menu item slug

Well you’ve Post ID with you. So you can use this custom function to retrieve slug of any post.

function get_the_slug( $id=null ){
    if( empty($id) ):
        global $post;
        if( empty($post) )
            return ''; // No global $post var available.
        $id = $post->ID;
    endif;

    $slug = basename( get_permalink($id) );
    return $slug;
}

This in return will provide you slug of specified post which you can pass as an argument. By default it’ll give you slug current post item.

Leave a Comment