Check if current page is category page in wordpress?

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

Related posts

Leave a Reply

4 comments

  1. you can use this for getting 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
    
  2. I have found the way to do it by checking if $cat_id is available or not on that page by the following.

    $cat_id = get_query_var('cat');
    

    Now we can check if $cat_id is available then it is a category page otherwise it is not.

  3. Amit’s answer will work but there is a simpler way as WordPress sets a Global var for the category id of $cat. So just checking if this is set will tell you if you are on a category page.

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