WordPress at a glance

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().

  • Global. WP_Query. $wp_query Global WP_Query instance.
✈ 1 time = 0.s = speed of light | 50000 times = 0.02s = 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";

Code of is_archive: wp-includes/query.php VER 4.9.8

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

Related Functions

From tag: Archives (of posts)

More from tag: Conditional tags (page type and request)

More from tag: Conditional tags (all)

More from category: Queries

More from Template Tags: Main Functions

No comments
    Hello, !     Log In . Register