How to get post slug in WordPress?

WordPress don’t have any built-in template function which returns a slug of current post like the_title() or the_content(). To get the slug of current post you can use following code;

Useful Read: How to Remove the Login Shake Effect in WordPress

//get post slug in WordPress
<?php
echo basename(get_permalink());
?>

 

Get post slug in WordPress

Get post slug in WordPress

4 Comments

Leave a Comment.