How to display the category slug and not the category name? : Back in 2008 there was a blog entry on how to do this. Throughout the comments of the article were about 15 different versions of how to accomplish getting different single.php templates for different categories. I went through them and combined them into what I feel is the best solution that keeps in tune with other WordPress naming conventions.

How to display the category slug and not the category name?

What is a Slug

slug is a few words that describe a post or a page. Slugs are usually a URL friendly version of the post title (which has been automatically generated by WordPress), but a slug can be anything you like. Slugs are meant to be used with permalinks as they help describe what the content at the URL is.

Example post permalink: http://wordpress.org/development/2006/06/wordpress-203/

The slug for that post is “wordpress-203”.

Category-Slug-660x182

What is a Post Slug

A few lowercase words separated by dashes, describing a post and usually derived from the post title to create a user-friendly (that is readable and without confusing characters) permalink. Post slug substitutes the “%posttitle%” placeholder in a custom permalink structure. Post slug should not be changed and is especially useful if the post title tends to be long or changes frequently.

First add the function below to your theme functions.php

The solution I got from the second thread worked perfectly for the category slug:

<?php
if (is_category( )) {
$cat = get_query_var('cat');
$yourcat = get_category ($cat);
echo 'the slug is '. $yourcat->slug;
}
?>

Now if someone can please tell me how to display the tag slug?

I use this in one of my themes (in the category.php template):

<?php /* used to create dynamic category link */
$curr_cat = single_cat_title( '', false );
$cat_id = get_cat_ID( $curr_cat );
$category_link = get_category_link ( $cat_id );
?>

You could probably strip out the category slug from the end of the ‘$category_link’ if you need the slug only.