How To Get Category Name In WordPress | Ultimate Guideline For Beginners

When you are publishing content on multiple topics, you may need to show category name. By adding a category name your visitors easily understand what the article is. Now the question is how to get category name in WordPress. In this article, I will show how easily you can add a category name in WordPress.

Adding Category Descriptions in WordPress

Category Descriptions in WordPress

Categories and tags are the two built-in taxonomies of WordPress. So, you can easily sort your content by adding tags and categories. But many users don’t know how WordPress get category name. So, here is the easy process. To add a category name in WordPress, log in to your WordPress Dashboard and hover over posts. Here you can see categories; click on it. 

Now, input your category name in the name input box. You can also add a custom slug for your category. For example, if you already have a few categories and you want to connect with those categories, select a Parent Category. You can also add a description under your category name, and your visitors may better know what the category is.

Get Category Name By ID In WordPress

If you have a woo-commerce site, you must have various products in multiple categories. It’s very easy to add woocommerce get category name by id. All you need to do is add this code to your themes post.php file. 

<?php

foreach((get_the_category()) as $category) {

  $postcat= $category->cat_ID;

  $catname =$category->cat_name;

  echo $postcat;

  echo $catname;

}

?>

Get Category Name By ID In WordPress

To get category id WordPress from your WordPress dashboard, hover over on appearance and click on theme editor. Next, select post.php from the right side of your display and paste this code here.

WordPress Get Category slug.

We have already discussed how the WordPress category slug works, but if you want to add a custom slug to the existing items of your categories. From your admin dashboard, hover over on posts and click on the category. Here you will find all the items of category. Now click on Quick Edit and input your desired slug for the category and save the changes.

Get Category Name in Archive Page

Now, most of the WordPress theme developed to show automatically category name in archive page. But how can you get category name in archive pages if your theme does not have the functionality?

From your WordPress Dashboard, hover over on appearance and click on Theme Editor and find the category.php from the right side of your display. Once you find the category.php, copy and paste the code here.

<?php

the_archive_description( ‘<div class=”taxonomy-description”>’, ‘</div>’ );

?>

After saving the changes, visit your archive pages to make sure that it is working or not.

How do I show category names in WordPress?

There are multiple ways for displaying the category name and displaying the category link in WordPress. To display the name of the category, add the code below in the post.php file.

<?php $cat = get_the_category(); echo $cat[0]->cat_name; ?>

Here, the number “0” displays the first category, so “1” will display the second category, “2” will display the third category, and so on.

To display a list of links to each category: If you have multiple categories, you should use this code to display a full list of links for each category.

<?php the_category(‘, ‘); ?>

Here, the comma ‘,’ serves as a separator when the post is included in more than one category. You can add multiple categories at a time by using “between two category names.

How do I find the category ID of a WordPress post?

After Log in to your wordpress dashboard, navigate to posts>categoris. Now, move the mouse over the name of the WordPress Category you would like to know the category’s ID and notice the URL at the bottom left corner of your browser. 

The link looks for the tag_ID=X on the browser, where X always carries the value of WordPress category ID.

How do I find the category ID of a WordPress post?

How do I find the tag name in WordPress?

Log in to your WordPress dashboard, hover over on posts>tags. Now, move the mouse over the name of the WordPress tags you would like to know the tag’s ID and notice the URL at the bottom left corner of your browser. The link looks for the tag_ID=X on the browser, where X always carries the value of WordPress tag ID.

Final Thought

So, We hope this article has helped you learn how to get category name in WordPress. If you are new to WordPress and struggling to start a WordPress blog, here are a few helpful resources to make your journey easier; just read our latest blog post on how you can create a blog today.

Read our Latest Post on: 

  1. Start a blog?
  2. Optimize Your WordPress Blog for SEO?
  3. Customize WordPress Blog?
  4. How to install wordpress themes?

Leave a Reply

Your email address will not be published. Required fields are marked *