• or97140

    (@or97140)


    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://ww.wp.xz.cn/plugins/custom-content-shortcode/

Viewing 1 replies (of 1 total)
  • Plugin Author Eliot Akira

    (@miyarakira)

    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.