Saturday, November 22, 2014

Wordpress: Get the slug from outside the loop

It is really simple to get the current slug on any page of a wordpress site. Useful for example if you do not want to create a different template for a minute alteration.

 <?php  
 global $post;  
 $slug = get_post( $post )->post_name;  
 echo $slug;  
 ?>