Title: Shortcode Count
Last modified: August 20, 2016

---

# Shortcode Count

 *  [julian.weinert](https://wordpress.org/support/users/julianweinert/)
 * (@julianweinert)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/shortcode-count/)
 * Hey guys!
 * I’m working on a plugin that creates HTML Code via a shortcode.
    Now I want to
   identify the created HTML when the shortcode gets called twice or more often.
 * Like:
 *     ```
       <div class="myClass-0"></div>
       <div class="myClass-1"></div>
       ```
   
 * Is there a way to count how many times a specific shortcode got called?
 * I tried this PHP code:
 *     ```
       if(!$count)
       {
           $count = 0;
       }
       else
       {
           $count = $count + 1;
       }
       ```
   
 * But it seems as the variable gets deleted after calling the shortcode one time.
   
   I also tried global variables… But all this didn’t seem to work.
 * Hope somebody can help me!
    Greets J.

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

 *  [Yong](https://wordpress.org/support/users/yong/)
 * (@yong)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/shortcode-count/#post-2531900)
 * I have the same question about this too, have you get solutions?
 * thanks.
 *  Thread Starter [julian.weinert](https://wordpress.org/support/users/julianweinert/)
 * (@julianweinert)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/shortcode-count/#post-2531901)
 * Oh yea!
    I got the solution but forgot to answer here.
 * So here you go:
 *     ```
       static $count;
       if(!$count)
       {
           $count = 0;
       }
       $count++;
       ```
   

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

The topic ‘Shortcode Count’ is closed to new replies.

## Tags

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

 * 2 replies
 * 2 participants
 * Last reply from: [julian.weinert](https://wordpress.org/support/users/julianweinert/)
 * Last activity: [14 years, 1 month ago](https://wordpress.org/support/topic/shortcode-count/#post-2531901)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
