Title: Embedding a Variable in shortcode
Last modified: August 19, 2016

---

# Embedding a Variable in shortcode

 *  Resolved [vanak](https://wordpress.org/support/users/vanak/)
 * (@vanak)
 * [15 years, 10 months ago](https://wordpress.org/support/topic/embedding-a-variable-in-shortcode/)
 * Hi,
 * I have shortcode tag on a template page like so…
 *     ```
       <?php
       echo do_shortcode('[nggallery id=1 template="galleryview"]');
       ?>
       ```
   
 * However, where it says ‘id=1’ I would like to insert a variable so the client
   can say which gallery id to use. But when I use ‘$gallery_id’ instead it doesn’t
   work so I was just wondering does anybody know the correct syntax to achieve 
   this?
 * Many thanks for any help/ advice.

Viewing 1 replies (of 1 total)

 *  Thread Starter [vanak](https://wordpress.org/support/users/vanak/)
 * (@vanak)
 * [15 years, 10 months ago](https://wordpress.org/support/topic/embedding-a-variable-in-shortcode/#post-1621809)
 *     ```
       <?php
       echo do_shortcode('[nggallery id='.$gallery_id.' template="galleryview"]');
       ?>
       ```
   
 * This worked, tried it yesterday and it didn’t work, tried it again today and 
   it did so I must of had a typo yesterday. Solved now anyway.

Viewing 1 replies (of 1 total)

The topic ‘Embedding a Variable in shortcode’ is closed to new replies.

## Tags

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

 * 1 reply
 * 1 participant
 * Last reply from: [vanak](https://wordpress.org/support/users/vanak/)
 * Last activity: [15 years, 10 months ago](https://wordpress.org/support/topic/embedding-a-variable-in-shortcode/#post-1621809)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
