Use wp_localize_script
to pass data from php to your javascript:
wp_register_script(
'wpa_script',
get_template_directory_uri() . '/js/script.js',
array('jquery'),
null,
false
);
wp_localize_script(
'wpa_script',
'WPAData',
array(
'slides' => array( 'http://google.com', 'http://google.co.uk' )
)
);
Related Posts:
- jQuery not available to other scripts
- Theme now uses require.js and enqueue script no longer works
- How to include jQuery and JavaScript files correctly?
- pass object/JSON to wp_localize_script
- jQuery in header or footer
- Is there a way to set the order of wp_footer hooked functions?
- What is the best practice for customizing a plugin’s JavaScript/jQuery?
- How to Change CSS Variable value in Theme Customizer Live Preview
- wp_enqueue_script being ignored in custom theme
- Getting jquery to work with custom theme
- Adding wp_enqueue_media(); causes problem
- How to correctly add JQuery in a WP theme?
- Difficulty loading jQuery with wp_enqueue_script
- How to: JQuery multiple wordpress media uploader buttons in the same options page?
- My jQuery is enqueued properly. So why isn’t it working?
- Enqueued JavaScript is not working
- How to register and enqueue JavaScript files without breaking plugin dependencies?
- add jquery file if a certain page is included
- how can i remove js file from my footer in wordpress
- How to enqueue scripts properly with ES6 webpack?
- change background image on scroll
- How would I get this to work – send to post from thick box
- enqueue script if page is not equal to
- Set start page depending on screen width [closed]
- can’t add EVENT LISTENER to a element
- jQuery Snippet Not Working on WordPress Site [closed]
- WP Customizer get control value on change
- Execute javscript when theme customizer loads (autosave issue)
- How to Use Webpack with WordPress Script Modules and Enqueue a Custom Class
- What is the preferred way to add custom javascript files to the site?
- ajaxurl not defined on front end
- Does the functions.php file ever get called during an AJAX call? Debug AJAX
- theme path in javascript file
- Solutions for generating dynamic javascript / CSS
- How to enqueue script if widget is displayed on page?
- force enqueue script to be first in order of prominence
- How to dequeue a script?
- Proper, exhaustive documentation for wp.editor etc
- Any alternate TinyMCE4 themes / subthemes?
- Move WordPress native javascript to bottom of page?
- Why I can’t add a CSS style in this WordPress theme?
- RequireJS in custom theme. Working Example
- The difference between calling wp_enqueue_scripts to load scripts and styles in custom theme
- Google Maps not displaying in wordpress using Google Maps Javascript API
- How to get a jQuery script to run on a page?
- Trigger Customizer saving process with Javascript only
- How to alter the text of the post “Excerpt” box label in WordPress post editor?
- What can I hook into after_setup_theme?
- What does “Do not deregister the jquery script in the administration area” mean?
- How to Add a .js file Only in one specific Page Dynamically to Head
- How do you enqueue script tags for ReactDOM in WordPress’ functions.php?
- Including javascript for a shortcode
- Asynchronous Javascript Loaders
- WordPress Enqueue Script Chaos (jQuery & Foundation.js)
- How do I “unhook” / de-register jQuery so that it’s not called as part of wp_footer();?
- using wp_enqueue_script to attach jquery-ui
- Use js script from one plugin in another plugin
- Changing the entire control choices using wp.customize with JavaScript
- Check javascript file Proper way in functions.php
- wp_enqueuescript won’t load in footer even with true value set?
- WordPress Google Maps in Custom Theme
- Modifying JS files in Child-theme
- How wp_enqueue_script works?
- Enqueued Stylesheets Effecting Admin Styles
- Enqueuing Script in functions.php vs on the page
- How do I get my page to load the jQuery UI Effects library?
- Whats the safest way to output custom JavaScript and Css code entered by the admin in the Theme Settings?
- WordPress Customizer Control with React
- Script won’t execute in the media manager
- How to properly add Bootstrap and JQuery Javascripts?
- How to configure wordpress to work with Vuejs with SSR and without hashbang
- Is it safe to enqueue a font style without putting http or https?
- How to hook CSS file according to theme selection in the customizer section
- using wordpress without javascript
- Toggle Sidebar Display
- Is there a filter for enqueue script to strip the type=”text/javascript” property
- Unhook jQuery from WooCommerce via `functions.php`? [closed]
- Fancy-box Esay wordpress plugin fails to work on Multilingual site
- Is my approach to enqueue styles inefficient?
- Enqueuing javascript files
- functions.php not hooking up with style.css
- way to include own functions independent of theme
- How to To Filter wp_enqueue_script() Scripts on Some Pages
- Problem in loading javascript in footer
- WP_enqueue_script() loads them always in wp_footer()?
- WP 3.1 upgrade breaks AutoFocus+ theme
- JavaScript Change focus to password field login page being reset
- WP site makes mobile browser crash for high memory usage
- How can i move my product name & price from below thumbnail to be the rollover content in Avada & Woocommerce?
- How to get the value entered in the input field in wordpres
- How react js and other Javascript Technologies works on WordPress plugin?
- Uncaught ReferenceError: tippy is not defined
- When trying to run build script with gutenberg (with SVG import) – Error: Plugin name should be specified
- Is there any halfway decent documentation on the wp.media JS class?
- WordPress Includes mejs 404 error
- Smooth Scrolling Animation of Image Between Two Containers (Elementor) Using JavaScript and GSAP
- Why is my JS not working on initial load?
- Selective styles and scripts inclusion
- How to add group-row to InnerBlock template?
- Javascript localization doesn’t load. How to Internationalize javascript without plugin?