Posted By

mihael on 06/29/10


Tagged

post wordpress name slug


Versions (?)

WordPress: Get the post slug


 / Published in: PHP
 

This function returns the slug fot the given post...

  1. // @ WordPress
  2. // Returns the post slug
  3. // Make sure to use this inside the loop
  4. //----------------------------------------------------------
  5. function the_slug($postID="") {
  6.  
  7. global $post;
  8. $postID = ( $postID != "" ) ? $postID : $post->ID;
  9. $post_data = get_post($postID, ARRAY_A);
  10. $slug = $post_data['post_name'];
  11. return $slug;
  12. }
  13. //----------------------------------------------------------
  14. // to display current post/page slug: <?php echo the_slug(); ?>
  15. // to display specific post/page slug add the post id parameter: <?php echo the_slug('23'); ?>
  16. // to get var: <?php $slug = the_slug(); ?> or <?php $slug = the_slug('23'); ?>

Report this snippet  

You need to login to post a comment.