Using category slug is the best way to use in wordpress custom query code as the category name does not always work. Rather use ‘category-slug’ instead, in this tutorial I’ll show you how to get WordPress slug in Category or in single page view.

For category view you can use this code snippet.

For single view or post view

Still hungry?

If in the case you only want to get category slug using category ID don’t worry folks, I’ve provided a solution on it too.

Step 1:

In your function.php file, put this function.

Step 2:

Once done, you can use the function like the below code.

Don’t know how to get WordPress Category ID?

Visit this link Get Single Taxonomy ID to learn more.

That’s it happy blogging, you can share your idea below.

Leave A Reply

Your email address will not be published.