Title: Shortcode in JS
Last modified: May 30, 2018

---

# Shortcode in JS

 *  Resolved [Nitrat](https://wordpress.org/support/users/nitrat/)
 * (@nitrat)
 * [7 years, 12 months ago](https://wordpress.org/support/topic/shortcode-in-js/)
 * Hello!
    Is it possible to insert a shortcode into javascript code? This option
   causes an error –
 * var a = do_shortcode(‘[gravitywp_count formid=”5″ number_field=”10″ created_by
   =”current”]’);

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

 *  Plugin Author [GravityWP](https://wordpress.org/support/users/gravitywp/)
 * (@gravitywp)
 * [7 years, 12 months ago](https://wordpress.org/support/topic/shortcode-in-js/#post-10342259)
 * Hi Nitrat,
 * You are mixing php and js I think.
 * `do_shortcode` is php. Try it without if the js is running in the content of 
   the page (not in a separate js file) or close and open php before and after if
   it’s in a php file.
 * Let us know if this helps.
 *  Thread Starter [Nitrat](https://wordpress.org/support/users/nitrat/)
 * (@nitrat)
 * [7 years, 12 months ago](https://wordpress.org/support/topic/shortcode-in-js/#post-10342285)
 * My js code is in the “html” field of the form. How to do this there?
 *  Plugin Author [GravityWP](https://wordpress.org/support/users/gravitywp/)
 * (@gravitywp)
 * [7 years, 12 months ago](https://wordpress.org/support/topic/shortcode-in-js/#post-10343011)
 * I have no idea if you can use js inside a HTML field. But if it’s possible, don’t
   use `do_shortcode`. You really only use that in php.
 *  Thread Starter [Nitrat](https://wordpress.org/support/users/nitrat/)
 * (@nitrat)
 * [7 years, 12 months ago](https://wordpress.org/support/topic/shortcode-in-js/#post-10343869)
 * Ok. What code is needed for php?
 *  Thread Starter [Nitrat](https://wordpress.org/support/users/nitrat/)
 * (@nitrat)
 * [7 years, 12 months ago](https://wordpress.org/support/topic/shortcode-in-js/#post-10359116)
 *     ```
       add_shortcode('mysum','tsum_mysum');
       function tsum_mysum() {
       	$li = do_shortcode('[gravitywp_count formid="5" field="10" created_by="current"]');
       return $li;      
              } 
       ```
   
 * So?
 *  Plugin Author [GravityWP](https://wordpress.org/support/users/gravitywp/)
 * (@gravitywp)
 * [7 years, 12 months ago](https://wordpress.org/support/topic/shortcode-in-js/#post-10359150)
 * Hi Nitrat,
 * You can use the shortcode on the frontpage without using do_shortcode. If you
   use it on a php page, than you use do_shortcode. I have no idea what you want
   to accomplish where, but this is not the way to do it. Start by reading the [docs here](https://developer.wordpress.org/reference/functions/do_shortcode/).
 * You’re question has nothing to do with the working of this plugin (the plugin
   does what it has to do). If you need help with custom code, please ask help from
   an expert on [Codeable](https://gravitywp.com/hire-gravity-forms-developers/).
 * Kind regards and good luck with your project,
 * Erik
 *  Thread Starter [Nitrat](https://wordpress.org/support/users/nitrat/)
 * (@nitrat)
 * [7 years, 12 months ago](https://wordpress.org/support/topic/shortcode-in-js/#post-10360342)
 * I guessed it myself! This code passes the value of “li” to the required field(
   dynamically populate)-
 *     ```
       add_filter('gform_field_value_li', 'gw_li');
       function gw_li() {
        $li = do_shortcode('[gravitywp_count formid="5" number_field="10" created_by="current"]');
       return $li;      
       }
       ```
   

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

The topic ‘Shortcode in JS’ is closed to new replies.

 * ![](https://ps.w.org/gravitywp-count/assets/icon-256x256.jpg?rev=3215193)
 * [GravityWP - Count](https://wordpress.org/plugins/gravitywp-count/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/gravitywp-count/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/gravitywp-count/)
 * [Active Topics](https://wordpress.org/support/plugin/gravitywp-count/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/gravitywp-count/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/gravitywp-count/reviews/)

 * 7 replies
 * 2 participants
 * Last reply from: [Nitrat](https://wordpress.org/support/users/nitrat/)
 * Last activity: [7 years, 12 months ago](https://wordpress.org/support/topic/shortcode-in-js/#post-10360342)
 * Status: resolved