To get the post or page slug within your loop
global $post; $slug = $post->post_name;
In this example we can get get the post or page slug with the ID of 7.
$slug = get_post_field( 'post_name', 7 );
p.s. I increased my AdSense revenue by 68% using AI 🤖. Read my Ezoic review to find out how.