Support

Account

Home Forums Front-end Issues Passing the_field() as a JS variable Reply To: Passing the_field() as a JS variable

  • I would use wp_localize_script https://codex.wordpress.org/Function_Reference/wp_localize_script

    You could also just echo the values into a script tag on the page, but localizing the script would be the preferred method for an external script.

    
    <script>
      // echo a php value into a js variable on page
      var map_url = '<?php  the_field('map_url'); ?>';
    </script>