A post’s or page’s slug can be retrieved by accessing the post object’s post_name property. There are several ways to get the current
Option 1: Use Global Post Variable
global $post; $post_slug=$post->post_name;
Option 2: Use the get_post_field Function
$slug = get_post_field( 'post_name', get_post() );
That’s all there is to it!