/ Published in: PHP

This function returns the slug fot the given post...
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// @ WordPress // Returns the post slug // Make sure to use this inside the loop //---------------------------------------------------------- function the_slug($postID="") { global $post; $postID = ( $postID != "" ) ? $postID : $post->ID; $post_data = get_post($postID, ARRAY_A); $slug = $post_data['post_name']; return $slug; } //---------------------------------------------------------- // to display current post/page slug: <?php echo the_slug(); ?> // to display specific post/page slug add the post id parameter: <?php echo the_slug('23'); ?> // to get var: <?php $slug = the_slug(); ?> or <?php $slug = the_slug('23'); ?>
Comments
