WordPress is_year() Function

Beginner
4 min read
Updated: Nov 2026
3 examples
Conditional tag

Definition

In WordPress, is_year() returns true on a yearly archive, the page that lists posts of one year. A typical URL is /2026/.

It does not match a monthly or daily archive. For those, use is_month() and is_day(). For all date archives, use is_date().

Syntax

Use it as the test of an if statement.

WordPress
if ( is_year() ) {
  // code for the true path
} else {
  // code for the false path
}
CallWhat it does
is_year()True only on a yearly archive.
is_month()True only on a monthly archive.
is_date()True on any date archive.

Print the year with get_query_var( 'year' ).

Full declaration
WordPress
is_year(): bool

Parameters

ParameterDescription
NoneThis function takes no parameters.

Return Value

Return ValueDescription
booltrue if the main query is for a yearly archive, otherwise false.

WordPress Examples

Three short theme examples. Each one shows what prints on the true path and the false path.

Example 1 — Yearly archive title

Print the year in a heading.

WordPress
<?php if ( is_year() ) {
  echo '<h1>Posts from ' . get_query_var( 'year' ) . '</h1>';
} ?>

How It Works

  1. is_year() is true when only a year is in the URL.
  2. get_query_var( 'year' ) returns the year.
  3. Month and day archives skip the code.

Example 2 — Year, month, or day

Choose text by archive type.

WordPress
<?php
if ( is_year() ) {
  echo 'Yearly archive';
} elseif ( is_month() ) {
  echo 'Monthly archive';
} elseif ( is_day() ) {
  echo 'Daily archive';
} ?>

How It Works

  1. Each test checks one kind of date archive.
  2. Only the first true branch runs.
  3. Other pages print nothing.

Example 3 — Compare with this year

Add a note for the current year.

WordPress
<?php if ( is_year() && get_query_var( 'year' ) == gmdate( 'Y' ) ) {
  echo 'This is the current year.';
} ?>

How It Works

  1. is_year() checks the archive type.
  2. gmdate( 'Y' ) returns the year now.
  3. The text is printed only when both match.

Frequently Asked Questions

It returns true or false (a bool). Use it inside an if statement.
No. A monthly archive makes is_month() and is_date() true, not is_year().
Use get_query_var( 'year' ) on a yearly archive.
is_year() is only for yearly archives. is_date() is true for year, month, day, and time archives.
Conditional tags need the main query. Call them in template files or on hooks such as wp or template_redirect, not directly at the top of functions.php.

Next: Function Index

Go back to the full list of WordPress conditional functions.

Conditional Functions Index →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

13 people found this page helpful