Generally, there may not be much instances where you need to get category slug using ID, but knowing the method will help you while handling certain WordPress themes. By using a simple php function you can get the category slug through ID.
Paste the below code in your theme’s functions.php file and save changes.
function get_cat_slug($cat_id) {
$cat_id = (int) $cat_id;
$category = &get_category($cat_id);
return $category->slug;
}
You can call the above function by using the below line of code.
<?php echo get_cat_slug(5); ?>
Since 5 is entered, the code will return the category slug corresponding to ID 5.









Comments on this entry (1 comment)
Did you like this post? You can share your opinion with us! Simply click here.