Check if the current page is a category page in Wordpress?

I need to insert some condition if the current page is a category page or not.

+4
source share
4 answers

I found a way to do this by checking if $cat_idthis page is available or not, as follows.

$cat_id = get_query_var('cat');

Now we can check if $ cat_id is available, this is the category page, otherwise it is not.

+6
source

you can use this to get a category

is_category();
is_category( '1' ); // where 1 is category id
is_category( 'test' ); // where test is category name
is_category( 'test-ing' ); // where test-ing is category slug
+3
source

Amit , , Wordpress var $cat. , , , .

if(!empty($cat)){ //do something just on a category archive page }
0

All Articles