Title: Using a variable in javascript snippet?
Last modified: August 16, 2024

---

# Using a variable in javascript snippet?

 *  Resolved [kindred](https://wordpress.org/support/users/kindred/)
 * (@kindred)
 * [1 year, 9 months ago](https://wordpress.org/support/topic/using-a-variable-in-javascript-snippet/)
 * So, I am using a post-snippet with javascript to generate the shopify purchase
   buttons.
 * I wanted to create a single snippet and pass the BookID into it by variable (
   that way, I only have to change the homepage shortcode and it would pull the 
   correct book)
   However, if I try to pass the bookid like so
 *     ```wp-block-code
       <div id='product-component-{bookid}'></div>
       ```
   
 * and then in the javascript section
 *     ```wp-block-code
           ShopifyBuy.UI.onReady(client).then(function (ui) {      ui.createComponent('product', {        id: '{bookid}',        node: document.getElementById('product-component-{bookid}'),...
       ```
   
 * and the shortcode
 *     ```wp-block-code
       [preorderbook 1234567890]
       ```
   
 * I get nothing… the variable is never passed….
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fusing-a-variable-in-javascript-snippet%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

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

 *  Plugin Support [Mirza Hamza](https://wordpress.org/support/users/hamza1010/)
 * (@hamza1010)
 * [1 year, 9 months ago](https://wordpress.org/support/topic/using-a-variable-in-javascript-snippet/#post-17985443)
 * Hello [@kindred](https://wordpress.org/support/users/kindred/),
 * Thanks for contacting us,
 * I hope you are doing well, We’ve informed our technical team about your issue,
   and they will work on it promptly. When we receive their response, we will get
   back to you. Our team is here to assist you. Thank you for your patience.
 * Thanks & Regards
   WP Experts Support Team
 *  Thread Starter [kindred](https://wordpress.org/support/users/kindred/)
 * (@kindred)
 * [1 year, 9 months ago](https://wordpress.org/support/topic/using-a-variable-in-javascript-snippet/#post-17985489)
 * I apologize…. I thought I had posted an update.
   There is no problem with the 
   module — I was using it incorrectly.
 * The correct syntax to use the shortcode with a variable is this… and now it works
   (
   Suggestion, make this easier to find in your FAQ)
 *     ```wp-block-code
       [preorderbook bookid="1234567890"]
       ```
   
 *  Plugin Support [Mirza Hamza](https://wordpress.org/support/users/hamza1010/)
 * (@hamza1010)
 * [1 year, 9 months ago](https://wordpress.org/support/topic/using-a-variable-in-javascript-snippet/#post-17989445)
 * Hello [@kindred](https://wordpress.org/support/users/kindred/),
 * Thanks for your suggestion, If you have any questions, feel free to reach out.
   We’re here to assist you.
 * Thank you

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

The topic ‘Using a variable in javascript snippet?’ is closed to new replies.

 * ![](https://ps.w.org/post-snippets/assets/icon-128x128.gif?rev=2545587)
 * [Post Snippets - Custom WordPress Code Snippets Customizer](https://wordpress.org/plugins/post-snippets/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/post-snippets/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/post-snippets/)
 * [Active Topics](https://wordpress.org/support/plugin/post-snippets/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/post-snippets/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/post-snippets/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [Mirza Hamza](https://wordpress.org/support/users/hamza1010/)
 * Last activity: [1 year, 9 months ago](https://wordpress.org/support/topic/using-a-variable-in-javascript-snippet/#post-17989445)
 * Status: resolved