Is it possible to write on the page (single post) to display text that changes depending on what kind of tag is specified in the record. I understand that correctly written. For example, through an associative array to make a couple TAG-TEXT. If the record is for the TAG that is specified in an array, it should be displayed corresponding to this tag TEXT. Do you understand what I want? I know there is a function in WordPress has_tag (), but what if I have too many tags?

What I want:

For example,

if (has_tag ('TAGNAME')) {
<p> TEXT tag TAGNAME </p>

elseif (has_tag ('TAGNAME1')) {
<p> TEXT1 tag TAGNAME1 </p>


and so on (all different tags and text)

But how to do it programmatically? Do not write the same each time the design elseif! Especially when the tag. Can not we all in the form of an array?

  $test = array ('TAGNAME' => 'TEXT',   'TAGNAME1' => 'TEXT1')

And then to carry out the inspection on the tag, and the withdrawal of the text you want?


Confusing but I think I have the gist of it...

Yes, you'd have to write a bunch of if/elseif conditionals or a switch, or loop though an array of tag names. This would be a pretty high maintenance approach.

Or you could go to wp-admin->Posts->Tags, fill out the description and use that.

$post_tags = get_the_tags();
// you may have more than one
foreach ($post_tags as $t) {
  if (!empty($v->description)) echo $v->description; // or whatever you want to do with it   


I don't know if there is any pattern to your TEXT and TAGNAME strings that might be useful.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.