This is what I could come up with, within init
like you said ! Even if you print the $GLOBALS
array, there is no way to check if the current page is an archive, is_archive
is also set to blank! But if you check the $_GET
array, the q
variable contains the current archive type being displayed. Using this I came up with a hack, I cannot guarantee you if it will work always! But you can try something around this!
<?php
add_action('init', 'q');
function q()
{
//echo '<pre>';
//print_r($_GET);
//echo '</pre>';
$q = $_GET['q'];
//Here you can substitute other 'archive' terms, say 'author', 'date' or '<custom taxonomy name>'. Use a switch case or nested if-else to check all the archive terms in your environment!
$pos = strpos($q, 'category');
if($pos !== false )
echo "CATEGORY ARCHIVE";
}
Hope this one works!