Using WordPress ‘is_category()’ PHP function

The is_category() WordPress PHP function determines whether the query is for an existing category archive page. If a specific category parameter is provided, it will also check if the query is for one of the specified categories.

Usage

is_category( $category );

Example:

if ( is_category( 'News' ) ) {
    echo 'You are browsing the News category.';
}

Parameters

  • $category (int|string|int|string, Optional) – Category ID, name, slug, or array of such to check against. Default: ''

More information

See WordPress Developer Resources: is_category()

Examples

Check if Any Category Archive Page

if ( is_category() ) {
    echo 'You are browsing a category archive page.';
}

Check Specific Category by ID

if ( is_category( 9 ) ) {
    echo 'You are browsing the category with ID 9.';
}

Check Specific Category by Name

if ( is_category( 'Stinky Cheeses' ) ) {
    echo 'You are browsing the Stinky Cheeses category.';
}

Check Specific Category by Slug

if ( is_category( 'blue-cheese' ) ) {
    echo 'You are browsing the Blue Cheese category.';
}

Check Multiple Categories

if ( is_category( array( 9, 'blue-cheese', 'Stinky Cheeses' ) ) ) {
    echo 'You are browsing one of the specified categories.';
}