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

I have the link like below :

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

Read More

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 ?

Related posts

3 comments

  1. If you want to get category details by category name, category slug, and category ID then you should use get_term_by().

    // Get term by name ''news'' in Categories taxonomy.
    $category = get_term_by('name', 'news', 'category')
    
    // Get term by name ''news'' in Tags taxonomy.
    $tag = get_term_by('name', 'news', 'post_tag')
    
    // Get term by name ''news'' in Custom taxonomy.
    $term = get_term_by('name', 'news', 'my_custom_taxonomy')
    
    // Get term by name ''Default Menu'' from theme's nav menus.
    // (Alternative to using wp_get_nav_menu_items)
    $menu = get_term_by('name', 'Default Menu', 'nav_menu');
    

    Reference Link

Comments are closed.