WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a function in WordPress that will check if the page you are on is a sub-category archive page?

Like the way is_category checks if it's a category page?

share|improve this question
up vote 2 down vote accepted

Sub-categories use the regular category archive page by default. There is no function such as is_subcategory. But you can write your own.

Here is an example: This will check if the current page is a sub-category. Or if you pass an ID it will check if the ID is a subcategory.

function is_subcategory( $cat_id = NULL ) {

        if ( !$cat_id )
            $cat_id = get_query_var( 'cat' );

        if ( $cat_id ) {

            $cat = get_category( $cat_id );
            if ( $cat->category_parent > 0 )
                return true;

        return false;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.