WordPress is_category() Function

Beginner
4 min read
Updated: Nov 2026
3 examples
Conditional tag

Definition

In WordPress, is_category() returns true on a category archive, the page that lists posts of one category.

Call it without an argument to match any category archive. Pass an ID, a name, or a slug to match one category. It does not tell you if a post belongs to a category. For that, use has_category().

Syntax

Use it as the test of an if statement.

WordPress
if ( is_category() ) {
  // code for the true path
} else {
  // code for the false path
}
CallWhat it does
is_category()True on any category archive.
is_category( 'news' )True on the archive of the news category (slug, name, or ID).
is_category( array( 'news', 'tips' ) )True on the archive of either category.

For tags use is_tag(). For custom taxonomies use is_tax().

Full declaration
WordPress
is_category( int|string|int[]|string[] $category = '' ): bool

Parameters

ParameterDescription
$categoryOptional. A category ID, name, slug, or an array of them. Default is empty, which means any category.

Return Value

Return ValueDescription
booltrue if the main query is for a category archive, otherwise false.

WordPress Examples

Three short theme examples. Each one shows what prints on the true path and the false path.

Example 1 — Any category archive

Print a label above the post list.

WordPress
<?php if ( is_category() ) {
  echo '<p>Category: ' . single_cat_title( '', false ) . '</p>';
} ?>

How It Works

  1. is_category() is true on category archives only.
  2. single_cat_title() returns the name when the second argument is false.
  3. Tag and date archives skip the code.

Example 2 — One category by slug

Show a banner only for the news category.

WordPress
<?php if ( is_category( 'news' ) ) {
  echo '<div class="banner">Latest company news</div>';
} ?>

How It Works

  1. 'news' is the category slug.
  2. Only that archive returns true.
  3. Other categories skip the banner.

Example 3 — is_category() vs has_category()

Learn the difference between a page type and a post fact.

WordPress
<?php
if ( is_category( 'news' ) ) {
  echo 'You are on the news archive.';
}
if ( has_category( 'news' ) ) {
  echo 'This post is in news.';
} ?>

How It Works

  1. is_category() asks what kind of page this is.
  2. has_category() asks about the current post.
  3. Pick the one that answers your question.

Frequently Asked Questions

It returns true or false (a bool). Use it inside an if statement.
Use has_category( 'news' ) or in_category( 'news' ) in the loop. is_category() is only for the archive page.
Yes. You can pass the ID, the name, or the slug, but the slug is the most stable.
No. It matches the category you name. Child categories need their own check.
Conditional tags need the main query. Call them in template files or on hooks such as wp or template_redirect, not directly at the top of functions.php.

Next: is_child_theme()

Check if a child theme is active.

is_child_theme() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful