WordPress at Your Fingertips

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

#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.

Code of is_archive() WP 5.8.1

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

Archives (of posts)

Conditional tags (page type and request)

Conditional tags (all)

Queries

Main Functions

vladlu 100vlad.lu
Editors: Kama 101
No comments
    Log In