Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the category name from category slug in wordpress?

Tags:

wordpress

I have the link like below :

http://localhost/rajab/product-category/pvc-hose/

the term "pvc-hose" is the category slug. I wanted to derive the category name from this slug name. I wanted to display the category name becaus the slug name is having the "-" in between.I dont want this when i am displaying the category slug. How to remove this ?

like image 692
nnnnnn Avatar asked Dec 02 '22 13:12

nnnnnn


1 Answers

Use get_category_by_slug. E.g.

<?php
$catObj = get_category_by_slug('category-slug'); 
$catName = $catObj->name;
?>
like image 63
Rob_jS Avatar answered Mar 07 '23 19:03

Rob_jS