Last active
August 29, 2015 14:11
-
-
Save mustardBees/46f2e821353ab53a92bd to your computer and use it in GitHub Desktop.
WordPress - get the slug of your post or page
This file contains 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 | |
/** | |
* 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