Last active
August 26, 2017 12:45
-
-
Save jasondmoss/7344278 to your computer and use it in GitHub Desktop.
Get WordPress Post 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 | |
/** | |
* Get post slug | |
* | |
* @param integer $objectId (Optional) Post ID | |
* @param boolean $echo (Optional) Whether to echo or return value. | |
* | |
* @return string | |
* @access public | |
*/ | |
function getSlug($objectId, $echo = false) | |
{ | |
if (empty($objectId)) { | |
global $post; | |
$objectId = $post->ID; | |
} | |
$postData = get_post($objectId, ARRAY_A); | |
$slug = $postData['post_name']; | |
return ($echo) ? _e($slug) : $slug; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment