Skip to content

Instantly share code, notes, and snippets.

@mustardBees
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mustardBees/46f2e821353ab53a92bd to your computer and use it in GitHub Desktop.
Save mustardBees/46f2e821353ab53a92bd to your computer and use it in GitHub Desktop.
WordPress - get the slug of your post or page
<?php
/**
* Get the slug of your post or page
*
* @author Tom Barrett
* @link http://goo.gl/95boK0
*/
function iweb_get_the_slug( $id = null ) {
if ( empty( $id ) ) {
global $post;
if ( empty( $post ) ) {
return ''; // No global $post var available
}
$id = $post->ID;
}
$slug = basename( get_permalink( $id ) );
return $slug;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment