Title: shortcode attrs as vars in javascript?
Last modified: August 30, 2016

---

# shortcode attrs as vars in javascript?

 *  [or97140](https://wordpress.org/support/users/or97140/)
 * (@or97140)
 * [11 years ago](https://wordpress.org/support/topic/shortcode-attrs-as-vars-in-javascript/)
 * Using version 2.3.0 of the plugin. I can access my shortcode attributes as variables
   in custom php code, but they dont seem to expand in custom javascript code the
   same way. For example, I have a custom attr “foo”. In my custom php code I can
   access the value for “foo” using $foo. However, when I use $foo in my custom 
   javascript, it just prints a literal “$foo” into the resulting html. I tried 
   using {foo} as well, but it also just printed a literal “{foo}”.
 * Is there any way I can refer to the value of a shortcode attr in my custom javascript?
   Thanks!
 * [https://wordpress.org/plugins/custom-content-shortcode/](https://wordpress.org/plugins/custom-content-shortcode/)

Viewing 1 replies (of 1 total)

 *  Plugin Author [Eliot Akira](https://wordpress.org/support/users/miyarakira/)
 * (@miyarakira)
 * [10 years, 12 months ago](https://wordpress.org/support/topic/shortcode-attrs-as-vars-in-javascript/#post-6224353)
 * I believe what you need is to echo the variable from PHP to pass it to JS. For
   example:
 *     ```
       <script>
   
         var foo = <?php echo json_encode($foo); ?>;
   
       </script>
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘shortcode attrs as vars in javascript?’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/custom-content-shortcode_766976.svg)
 * [Custom Content Shortcode](https://wordpress.org/plugins/custom-content-shortcode/)
 * [Support Threads](https://wordpress.org/support/plugin/custom-content-shortcode/)
 * [Active Topics](https://wordpress.org/support/plugin/custom-content-shortcode/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/custom-content-shortcode/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/custom-content-shortcode/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [Eliot Akira](https://wordpress.org/support/users/miyarakira/)
 * Last activity: [10 years, 12 months ago](https://wordpress.org/support/topic/shortcode-attrs-as-vars-in-javascript/#post-6224353)
 * Status: not resolved