Get the slug

There is no defined function in WordPress to get the slug of the current post. With the following function you can get the slug. The function holds one parameter:

If true the slug will be echoed.

// Get the slug
function the_slug( $echo = true ) {
	$slug = basename( get_permalink() );
	do_action( 'before_slug', $slug );
	$slug = apply_filters( 'slug_filter', $slug );
	if ( $echo ) 
   	echo $slug;
	do_action( 'after_slug', $slug );
	return $slug;