WordPress function like is_category for subcategory? is_subcategory?

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;
    }

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)