Return to Snippet

Revision: 28029
at July 13, 2010 00:23 by mihael


Updated Code
// @ 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'); ?>

Revision: 28028
at June 29, 2010 23:44 by mihael


Initial Code
// @ WordPress
// Returns the post slug
// Make sure to use this inside the loop
//----------------------------------------------------------
function the_slug() {
	global $post; // get the post
	$post_data = get_post($post->ID, ARRAY_A);
	$slug = $post_data['post_name'];
	return $slug;
}
//----------------------------------------------------------
// to display: <?php echo the_slug(); ?>
// to get var: <?php $slug = the_slug(); ?>

Initial URL


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

Initial Title
WordPress: Get the post slug

Initial Tags
post, wordpress

Initial Language
PHP