Skip to content

Instantly share code, notes, and snippets.

@ruthtillman
Created July 17, 2014 19:09
Show Gist options
  • Select an option

  • Save ruthtillman/7b0337cddfed76421b84 to your computer and use it in GitHub Desktop.

Select an option

Save ruthtillman/7b0337cddfed76421b84 to your computer and use it in GitHub Desktop.
Wordpress: globally-isolating a page's slug.
function get_the_slug( $id=null ){
if( empty($id) ):
global $post;
if( empty($post) )
return ''; // No global $post var available.
$id = $post->ID;
endif;
$slug = basename( get_permalink($id) );
return $slug;
}
/* Actually returns slug kinda */
/**
* Display the page or post slug
*
* Uses get_the_slug() and applies 'the_slug' filter.
*/
function the_slug( $id=null ){
echo apply_filters( 'the_slug', get_the_slug($id) );
}
/* This is how to use slug */
/* <?php the_slug(); ?> */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment