is_archive() doesn’t work on public query var archive pages?

Try this:

add_action( 'template_redirect', 'my_test_if_archive' );

function my_test_if_archive() {
  global $wp_query;
  $qv = array_keys( $wp_query->query );
  $archives = array('year', 'monthnum', 'day', 'w', 'm', 'author', 'post_type');
  $is_archive = ! empty( array_intersect( $qv, $archives ) );
  $is_tax = ! empty( $wp_query->tax_query->queries );
  if ( $is_archive || $is_tax ) {
    // this is an archive
  }
}

Leave a Comment