Title: has tag
Last modified: August 30, 2016

---

# has tag

 *  [Feritel](https://wordpress.org/support/users/feritel/)
 * (@feritel)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/has-tag/)
 * I need help with code that I found here:
    [https://wordpress.org/support/topic/using-has_tag-to-display-certain-information?replies=8](https://wordpress.org/support/topic/using-has_tag-to-display-certain-information?replies=8).
 *     ```
       <?php
       // Array of tags to check for
       $find_tags = array( 'Actress', 'Model', 'Singer' );
   
       // Array to store matched tags
       $found_tag = array();
   
       // Seperator that sits between each result
       $seperator = ',';
   
       // If we have any one(or more) of the tags
       if( has_tag( $find_tags ) ) :
   
       	// Loop over the tag array
       	foreach( $find_tags as $p_tag ) :
   
       		// If this is a matching tag add to array
       		if( has_tag( $p_tag ) )
       			$found_tag[] = "<a href='http://example.com/tag/$p_tag'>$p_tag</a>";
   
       		continue;
       	endforeach;
   
       	// Join the results together using the seperator if applicable
       	echo  '<li class="occupation">Occupation: '. implode( $seperator, $found_tag ) . '</li>';
       endif;
       ?>
       ```
   
 * ?
 *     ```
       $found_tag[] = "<a href='http://example.com/tag/$p_tag'>need here NAME OF TAGS</a>";
       ```
   

Viewing 6 replies - 1 through 6 (of 6 total)

 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/has-tag/#post-6748880)
 * Huh, they are not really valid tag slugs either – using uppercase is a bad practice.
   Anyway, I would change the array structure to check posts against to associative`'
   slug' => 'Name',` form. Then when you `foreach` through the array, use this form:`
   foreach( $find_tags as $slug => $name )`
 * Then your anchor string becomes `"<a href='http://example.com/tag/$slug/'>$name
   </a>"`
 *  Thread Starter [Feritel](https://wordpress.org/support/users/feritel/)
 * (@feritel)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/has-tag/#post-6748917)
 * Thanks for your answer. But I asked the wrong question. I am very sorry. I need
   not slug. I need show name of tag.
    For eg slug name: array( ‘actress’, ‘model’,‘
   singer’ ); Must show me titles for each tags (for eg): [Best actress](http://example.com/tag/actress/)
   [Successful models](http://example.com/tag/model/) [The most gifted singer](http://example.com/tag/singer/)
 *  Thread Starter [Feritel](https://wordpress.org/support/users/feritel/)
 * (@feritel)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/has-tag/#post-6748918)
 * Must show me titles for each tags (for eg):
 *     ```
       <a href='http://example.com/tag/actress/'>Best actress</a><br />
       <a href='http://example.com/tag/model/'>Successful models</a><br />
       <a href='http://example.com/tag/singer/'>The most gifted singer</a>
       ```
   
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/has-tag/#post-6748934)
 * I understood what you wanted the first time, but you’re not seeing how my answer
   will actually work for you even though you’ve rephrased the question. Don’t worry,
   no problem, I’ll rephrase my answer and maybe you will then understand.
 * The thing is you need _both_ a slug and a name for the output you desire. You
   must have a slug in the permalink, but slugs are ugly for link text, so you want
   the more attractive name. Thus you need to define an array that provides both
   types of data. There are a few ways to do this, I suggest this:
 *     ```
       $find_tags = array(
          'actress' => 'Best actress',
          'model' => 'Successful models',
          'singer' => 'The most gifted singer',
       );
       ```
   
 * Using this method, the link text does not actually need to be the tag name, it
   can be any string you like. The actual name is fine though. You could also write
   additional code to get the name from the DB based on the slug, but since the 
   slug array is hardcoded, it’s easy enough to hardcode the names as well.
 * Then alter the related part of your code like so:
 *     ```
       foreach( $find_tags as $slug => $name ) :
          if( has_tag( $slug ) )
          $found_tag[] = "<a href='http://example.com/tag/$slug/'>$name</a>";
       ```
   
 * I suspect you not seeing how this will work for you is just because you’re unfamiliar
   with coding this type of array structure. Study carefully my suggested changes,
   temporarily echo or print_r the various variables involved until you understand
   how this type of structure works. It is a very useful thing to know.
 *  Thread Starter [Feritel](https://wordpress.org/support/users/feritel/)
 * (@feritel)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/has-tag/#post-6749019)
 * You are right I don’t understood first time. I am very grateful for your help.
   You really very help me! Many-many thanks!
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/has-tag/#post-6749032)
 * You’re welcome! Your misunderstanding was my doing – I didn’t explain thoroughly
   enough the first time out of laziness, my bad.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘has tag’ is closed to new replies.

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 6 replies
 * 2 participants
 * Last reply from: [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * Last activity: [10 years, 8 months ago](https://wordpress.org/support/topic/has-tag/#post-6749032)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
