Display text on page with specific tag in wordpress

I want to display a text with a specific tag in wordpress.

Ex: I have 2 tags: car and boat, and 2 text: “I have car and i want one bike”, “I have boat and i am happy”

Read More

I want to display in header specific text when exist tag.

I try using tem exist in header.php but display text in all pages, not just in page where exist tag.

Ex:

 <?php
$boat = term_exists('boat', 'post_tag');
if ($boat !== 0 && $boat !== null) {
  echo "I have boat and i am happy!";
}
    ?>

Related posts

Leave a Reply

1 comment

  1. If you have only two tags this will do.

    <?php 
    if (is_tag( 'boat' )) {
        echo "I have boat and i am happy!";
    } elseif (is_tag('car'))   {
        echo "I have a car";
    }
    ?>