Check if its tag page or category page in WordPress

As we have seen in our previous post “How to display WordPress Categories on home page of website” we added Category index into our home page, and we added subcategories into Category archive page, but while doing it started showing category index onto our tag pages also, hence we now needed to distinguish whether we are on tag archive page or category archive page so we can hide categories from tag pages.

WordPress provides following API’s for the same,

  • is_category – Returns TRUE if we are on category archive page
  • is_tag – Returns TRUE if we are on tag archive page

The related code implementation will look like as below,

<?php if (is_category()) { ?>
    //this is category archive page
<?php } elseif (is_tag()) { ?> 
        //this is tag archive page
<?php } ?>

You can find more details about identifying different archive pages at https://codex.wordpress.org/Function_Reference/is_archive

Ezoic Title Tag Tester - Improve yo... x
Ezoic Title Tag Tester - Improve you CTR

Leave a Comment

Sign up to our newsletter!

ADB Commands Android Android Applications Android Build system Application Libraries Application Stack / User Interface Bash / Shell Scripts Bluetooth driver Cloud Technologies Commands and Packages Compilation Content Management System Core Kernel C Programs Development, Debugging and Performance Tools Development and Build Development Environment Setup Django & REST Api Errors & Failures Git Hardware Platforms HTML JAVA Programs Linux, OS Concepts and Networking Linux Device Drivers Linux Host, Ubuntu, SysAdmin Linux Kernel Linux Networking Middleware Libraries, HAL Multimedia NDK / Middleware / HAL Operating System Concepts PHP Programming Languages Scripting and Automation Search Engine Optimisation ( SEO ) Social Media Source Code Management ( SCM ) System Administration, Security Testing and Debugging Uncategorized Web Design and Development Website Hosting Wordpress Yocto Embedded Linux