I need the post slug…

March 1st, 2011 at 12:44am Jason 200 views

There is a function (get_post) that let us pick any part out of it, so we can end up with this code within the loop.

<?php // Get the Slug to use as the link
  $extrapostdata = get_post(the_ID(), ARRAY_A);
  $slug = $extrapostdata['post_name'];
 ?>
<h2><a href="/<?php echo($slug); ?>"><?php the_title(); ?></a></h2>

Another Codes: Here is a function that gives you the actual slug

function the_slug() {
	$post_data = get_post($post->ID, ARRAY_A);
	$slug = $post_data['post_name'];
	return $slug;
}

Put the above code in your templates function.php, then you can use:

<?php echo the_slug(); ?>

in your template to get the slug.

via-1: http://wordpress.org/support/topic/i-need-the-post-slug
via-2: http://wordpress.org/support/topic/solved-slug-as-string?replies=6
via-3: http://www.joshstauffer.com/get-post-slug-in-wordpress/

Entry Filed under: WordPress Tagged with:

Share This Post Share This Post SubscribePrint This Post Print This PostSave As PDF Save As PDF

Related Posts Hot Posts Hot Comments Hot Tags

      1 Comment Add your own

      • 1. fendi ahmad  |  April 24th, 2011 at 3:59 pm

        I was googling then I found this tutorial is most relevant to get parent slug of my post, easy to understand. Thank You.

      Leave a Comment

      Required

      Required, hidden

      Some HTML allowed:
      <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

      Trackback this post  |  Subscribe to the comments via RSS Feed


      Calendar

      March 2011
      MTWTFSS
      « Feb Apr »
       123456
      78910111213
      14151617181920
      21222324252627
      28293031 

      Sponsors

      Most Recent Posts