I’ve been looking for a way to customize the text shown on Tag pages. For some Tag pages, I’d like to include additional information related to the topic. For example, on the World of Warcraft tag page I might want to include information about my toons and links to the WoW Armory.
The official WordPress documentation, which is in general subpar, suggests creating a tag-[tag].php template for each tag you want to customize. So for my WoW example, I’d create a tag-world-of-warcraft.php template and include the custom changes there. And then do that for potentially hundreds of tags. And then edit each of those templates anytime something changes. No thanks.
A better solution is to use conditionals in the tag template in conjunction with a text substitution plugin such as AnyVar.
AnyVar lets you create text substitutions that can be placed anywhere within a site. For example, for my World of Warcraft example, I can compose a couple paragraphs about WoW and assign in to world-of-warcraft-var. Then, in the template, I just surround it in brackets like this: [world-of-warcraft-var], and AnyVar will handle inserting my text there. Anytime I want to update that text, I simply go in to AnyVar, change the text there, and it gets updated instantly.
Then it’s just a matter of inserting something like this into the tag.php template:
<?php /* If this is the World of Warcraft tag archive */ if( is_tag(world-of-warcraft)) { ?>
[world-of-warcraft-var]
<?php /* If this is a tag archive */ } elseif (is_tag()) { ?>
<h1><?php single_tag_title(); ?></h1>
Obviously you’ll need a separate if(is_tag(tag-name)) conditional for each tag that is going to have any customized content.
It’d be nice if there was a plugin that would do this automatically, but this is fairly straightforward and a lot easier than littering a site with dozens of different tag templates.