Created
June 25, 2013 15:29
-
-
Save yourdesigncoza/5859410 to your computer and use it in GitHub Desktop.
function to get post/page slug When coding or styling a theme, it can be very useful to be able to get the slug of the current post or page, for example to create a css class. Here’s an easy function to get the slug from the current post or page. source : http://www.wprecipes.com/wordpress-function-to-get-postpage-slug
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
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. | |
<?php echo the_slug(); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment