Support » Plugin: GravityWP - Count » Shortcode in JS

  • Resolved Nitrat

    (@nitrat)


    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

    (@gravitywp)

    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.

    My js code is in the “html” field of the form. How to do this there?

    Plugin Author GravityWP

    (@gravitywp)

    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.

    Ok. What code is needed for php?

    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

    (@gravitywp)

    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.

    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.

    Kind regards and good luck with your project,

    Erik

    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.