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 );
Let me know if this helped. Follow me on Twitter, Facebook and YouTube, or 🍊 buy me a smoothie.
p.s. I increased my AdSense revenue by 200% using AI 🤖. Read my Ezoic review to find out how.