is_archive()WP 1.5.0

Conditional tag. Return true when any of the archive pages are shown (Year, Category, Author, Post Type archive...).

Archive pages include category pages, tags, author pages, Post Type archive, and archive pages by date. So, is_archive() includes checks for is_category(), is_tag(), is_author(), is_day(), is_month(), is_year(), and so on.

Archive pages refer to pages of custom taxonomies (single-level or multi-level does not matter): is_tax().

1 time — 0. sec (speed of light) | 50000 times — 0.02 sec (speed of light) | PHP 7.2.5, WP 4.9.6

No Hooks.

Return

true|false. true if it is an archive page and false if not.

Usage

<?php if( is_archive() ){ ... } ?>

Examples

0

#1 Let's print the inscription "Category Page"

Check if this is a category page, print "Category Page", and if it is any other archive page, display the words "Archive Page":

if( is_category() )
	echo "Category Page";
elseif( is_archive() )
	echo "Archive Page";

Notes

Changelog

Since 1.5.0 Introduced.

is_archive() code WP 6.6.2

function is_archive() {
	global $wp_query;

	if ( ! isset( $wp_query ) ) {
		_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' );
		return false;
	}

	return $wp_query->is_archive();
}