Home › Forums › General Issues › Using a the_field in Javascript › Reply To: Using a the_field in Javascript
this looks like a script that is included using a script tag with an url like.
<script src="path/to/script">
PHP to output anything to do with WP cannot be added to such a script. To add directly to this you would need to output the script inside of a template file something like
?>
<script>
// code of script here.
</scrip>
<?php
So that it is part of the HTML page and not a separate .js file
To add variable values to the type of script you are using it must be registered, localized and enqueued using WP hooks and actions https://developer.wordpress.org/reference/functions/wp_localize_script/
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.