Skip to content

Instantly share code, notes, and snippets.

@nguyenvanduocit
Created June 8, 2013 19:43
Show Gist options
  • Save nguyenvanduocit/5736349 to your computer and use it in GitHub Desktop.
Save nguyenvanduocit/5736349 to your computer and use it in GitHub Desktop.
Lấy slug của một term,
function single_term_slug( $prefix = '', $display = true ) {
$term = get_queried_object();
if ( !$term )
return;
if ( is_category() )
$term_slug = apply_filters( 'single_cat_slug', $term->slug );
elseif ( is_tag() )
$term_slug = apply_filters( 'single_tag_slug', $term->slug );
elseif ( is_tax() )
$term_slug = apply_filters( 'single_term_slug', $term->slug );
else
return;
if ( empty( $term_slug ) )
return;
if ( $display )
echo $prefix . $term_slug;
else
return $term_slug;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment