Title: Adding a tag in a function
Last modified: December 7, 2024

---

# Adding a tag in a function

 *  [sacconi](https://wordpress.org/support/users/sacconi/)
 * (@sacconi)
 * [1 year, 6 months ago](https://wordpress.org/support/topic/adding-a-tag-in-a-function/)
 * I should add a tag in the following function:
 *     ```wp-block-code
       if (has_tag('wi-fi', $post)) {   $wi_fi_esc = esc_html__(get_the_author_meta( 'wi_fi_esc', $post->post_author ), 'sacconicase');   if(!empty($wi_fi_esc)){        $wi_fi_esc = '<div class="wi_fi_esc">'. $wi_fi_esc .'</div>';   }} else {    // don't have 'wi-fi' tag    $wi_fi_esc = '';}
       ```
   
 * I need not only ‘wi-fi’ but also ‘light-wi-fi-navigazione-social-controllo-posta-
   no-streaming-o-download’, I just put a comma and enter the other tag ? they dont
   have to be checked at the same time, it would be a non-sense, but the function
   can ignore it because I dont do it myself
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fadding-a-tag-in-a-function%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

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

 *  Moderator [threadi](https://wordpress.org/support/users/threadi/)
 * (@threadi)
 * [1 year, 6 months ago](https://wordpress.org/support/topic/adding-a-tag-in-a-function/#post-18184781)
 * According to the manual, you can also pass an array of terms to be checked to
   has_tag(): [https://developer.wordpress.org/reference/functions/has_tag/](https://developer.wordpress.org/reference/functions/has_tag/)
 * However, you must then read the values individually, as get_the_author_meta()
   only allows one term. See: [https://developer.wordpress.org/reference/functions/get_the_author_meta/](https://developer.wordpress.org/reference/functions/get_the_author_meta/)
 * I would recommend a foreach loop for this, which then assembles the string.
 * One more note: escape functions should only be used in the output. Therefore,
   replace esc_html__() with __() and use esc_html() in the output:
 *     ```wp-block-code
       $wi_fi_esc = '<div class="wi_fi_esc">'. esc_html( $wi_fi_esc ) .'</div>';
       ```
   
 *  Thread Starter [sacconi](https://wordpress.org/support/users/sacconi/)
 * (@sacconi)
 * [1 year, 6 months ago](https://wordpress.org/support/topic/adding-a-tag-in-a-function/#post-18184809)
 * it’s not so simple for me, so, since I never use the 2 tags at the same time (
   they are alternative), I’ll do 2 functions, one for each tag, changing a little
   bit the names

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

The topic ‘Adding a tag in a function’ is closed to new replies.

## Tags

 * [php](https://wordpress.org/support/topic-tag/php/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 2 replies
 * 3 participants
 * Last reply from: [sacconi](https://wordpress.org/support/users/sacconi/)
 * Last activity: [1 year, 6 months ago](https://wordpress.org/support/topic/adding-a-tag-in-a-function/#post-18184809)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
