CODE CODIFY.CLUB

WordPress Get category slug using category ID

First, put the following function in your functions.php file:

function get_cat_slug($cat_id) {
$cat_id = (int) $cat_id;
$category = &get_category($cat_id);
return $category->slug;
}

Once done, you can call the function as shown below:
<?php echo get_cat_slug(21); ?>
This will display the slug for the category with the ID 21.

V!ral

Developer, Technology aficionado, Beer Lover and founder of codify.club Network. Who shares a keen interest about website development, health issues, cancer awareness and other fun stuff.

Add comment

Follow us

Don't be shy, get in touch. We love meeting interesting people and making new friends.

Most popular

Most discussed