How To Get The Slug Of Current Post

Post or Page slug is simply the direct permalink or URL to the blog post. Following are the ways to get the slug of the current post.

1. Using basename() and get_permalink()

2. Using global $post object

3. Here’s an easy function to get the slug from the current post or page. Add this function into your functions.php file.

Call the function where you want to show in the page.

You may also be interested to learn about display shortcode in templates, wrap images in div, wp_query pagination and use different single template per category.