Title: get post tags as php function
Last modified: August 20, 2016

---

# get post tags as php function

 *  Resolved [Patrick Orr](https://wordpress.org/support/users/patrick-orr/)
 * (@patrick-orr)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/get-post-tags-as-php-function/)
 * Hey there,
    I need to get post tags as a php function, I used the function reference
   to try to set this up but it just returns nothing.
 * Does anyone have any ideas?
 * _[Code moderated as per the [Forum Rules](http://codex.wordpress.org/Forum_Welc ome).
   Please use the [pastebin](http://wordpress.pastebin.com/)]_

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

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/get-post-tags-as-php-function/#post-2146660)
 * `the_tags()` or `get_the_tags()` is already a php function;
    what are you trying
   to achieve with the tag data?
 * [http://codex.wordpress.org/Function_Reference/get_the_tags](http://codex.wordpress.org/Function_Reference/get_the_tags)
   
   [http://codex.wordpress.org/Function_Reference/the_tags](http://codex.wordpress.org/Function_Reference/the_tags)
 *  Thread Starter [Patrick Orr](https://wordpress.org/support/users/patrick-orr/)
 * (@patrick-orr)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/get-post-tags-as-php-function/#post-2146664)
 * Thanks,
    I am trying to use a tag as a class for a div which ties into a jquery
   menu that I have built.
 * It looks like this so far:
 * _[Code moderated as per the [Forum Rules](http://codex.wordpress.org/Forum_Welcome).
   Please use the [pastebin](http://wordpress.pastebin.com/)]_
 * I cant seem to get it to put the tags in though:( Do you have any ideas about
   how I should go about it?
 *  Thread Starter [Patrick Orr](https://wordpress.org/support/users/patrick-orr/)
 * (@patrick-orr)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/get-post-tags-as-php-function/#post-2146669)
 * This seem to work:
 *     ```
       <?php
       $posttags = get_the_tags();
       $count=0;
       if ($posttags) {
         foreach($posttags as $tag) {
           $count++;
           if (1 == $count) {
             echo $tag->name . ' ';
           }
         }
       }
       ?>
       ```
   

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

The topic ‘get post tags as php function’ is closed to new replies.

 * 3 replies
 * 2 participants
 * Last reply from: [Patrick Orr](https://wordpress.org/support/users/patrick-orr/)
 * Last activity: [14 years, 11 months ago](https://wordpress.org/support/topic/get-post-tags-as-php-function/#post-2146669)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
