Title: Add a variable inside a shortcode?
Last modified: August 19, 2016

---

# Add a variable inside a shortcode?

 *  [hyperburst](https://wordpress.org/support/users/hyperburst/)
 * (@hyperburst)
 * [16 years, 8 months ago](https://wordpress.org/support/topic/add-a-variable-inside-a-shortcode/)
 * Wondering how it might be possible to use a variable inside of a shortcode.
    
   I have a function that returns the current category number to a variable ($mycatid)
   and I would like to “pass” this number into the shortcode of a plugin I have 
   installed “AZINDEX” in place of the “1” shown below. (somehow substitute $mycatid
   for the number)
 * My PHP is pretty limited but I understand that the shortcode is seen as a string.
   Any ideas how I should approach this problem?
 * ‘<?php $mycatid = getCurrentCatID();
    echo do_shortcode(‘[az-index id=”1″]’);?
   >’

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

 *  [iridiax](https://wordpress.org/support/users/iridiax/)
 * (@iridiax)
 * [16 years, 8 months ago](https://wordpress.org/support/topic/add-a-variable-inside-a-shortcode/#post-1218059)
 * You could try modifying what’s going on in the plugin file itself and leave the
   shortcode in the post unmodified.
 *  [saythissaythat](https://wordpress.org/support/users/saythissaythat/)
 * (@saythissaythat)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/add-a-variable-inside-a-shortcode/#post-1218402)
 * Not sure if you figured this out long ago when you posted this, but I thought
   maybe the answer could help someone else out there.
 *     ```
       <?php $mycatid = getCurrentCatID();
       echo do_shortcode('[az-index id="'.$mycatid.'"]'); ?>
       ```
   
 *  [jrack](https://wordpress.org/support/users/jrack/)
 * (@jrack)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/add-a-variable-inside-a-shortcode/#post-1218414)
 * Hey saythissaythat.
 * Would that work for the post ID or other system variables as well? Slightly different
   syntax?
 * Thanks.

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

The topic ‘Add a variable inside a shortcode?’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 4 participants
 * Last reply from: [jrack](https://wordpress.org/support/users/jrack/)
 * Last activity: [16 years, 1 month ago](https://wordpress.org/support/topic/add-a-variable-inside-a-shortcode/#post-1218414)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
