On my category pages, I would like to get the name of the current category, compare it with the values of an array and display it (as a page header, but without a link on it), if the name is identical to one of the strings in the array (meaning: on certain category pages I want to display the category name as a title, on others not). All that above/outside the loop.
I tried this (inside category.php
):
<?php
$visible_titles = array("string1", "string2", "string3");
if(in_array(the_category(), $visible_titles)) {
echo "<h1>";
the_category();
echo "</h1>";
}
?>
But from that I get a wrong result: - The category name is displayed as a link even if it's not in the array - The content of the if-clause is never echoed
I also tried to use single_cat_title();
, but that (just like the_category
) also just echoes the category name as a link – I can't use it as a string to compare it to the values in my array, and I can't display it without it being a link.
What template tag or function can I use to get the desired result?