Here’s the function. Copy it and paste it into your functions.php file:
1 2 3 4 5 | function the_slug() { $post_data = get_post( $post ->ID, ARRAY_A); $slug = $post_data [ 'post_name' ]; return $slug ; } |
Once done, simply call the function within the loop to get the post or page slug.
1 | < ?php echo the_slug(); ?> |
Thanks to Maidul for the function!