Skip to content

Instantly share code, notes, and snippets.

@yourdesigncoza
Created June 25, 2013 15:29
Show Gist options
  • Save yourdesigncoza/5859410 to your computer and use it in GitHub Desktop.
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
<?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