I found out about wp_localize_scripts
here and it solves my issue:
functions.php
$var=get_current_user_id();
$params = array(
'max' => $var
);
wp_localize_script( 'myscript', 'MyScriptParams', $params );
wp_enqueue_script('myscript');
and in the .js
file I can retrieve this variable with MyScriptParams.max
.
Related Posts:
- Move WordPress native javascript to bottom of page?
- RequireJS in custom theme. Working Example
- How to get a jQuery script to run on a page?
- Including javascript for a shortcode
- Asynchronous Javascript Loaders
- wp_enqueuescript won’t load in footer even with true value set?
- How wp_enqueue_script works?
- How do I get my page to load the jQuery UI Effects library?
- Script won’t execute in the media manager
- How to properly add Bootstrap and JQuery Javascripts?
- Enqueuing javascript files
- Searching multiple tags and adding jQuery dependant script onto page template?
- Plugin Scripts no loading on options page
- How to enque js script in footer that are not in .js file?
- Loading scripts on a single page plants the script in the footer
- Including Older Version of jQuery for IE7/IE8
- How To Include JavaScript Files Only In Single Posts?
- How to make JQuery load on top of head tag before everything
- JavaScript code do not works on online server
- Bootstrap with separate js File
- How to add JS snippet before closing tag?
- Enqueue javascript that inserts custom php widget into jQuery-constructed div
- How to Run a jQuery Script after a Javascript Script has Finished in WordPress
- javascript not loading in wordpress
- bootstrap-slider.js by seiyria not working in wordpress
- What does [object Object] mean? (JavaScript)
- Why does my JavaScript code receive a “No ‘Access-Control-Allow-Origin’ header is present on the requested resource” error, while Postman does not?
- Javascript Runtime error: $ is undefined
- How to read data From *.CSV file using javascript?
- How to call a webservice method from an html page [javascript] with out refresh the page
- Enqueue core jQuery in the footer?
- How to correctly include jquery-ui effects on wordpress
- I want to enqueue a .js file to my child theme
- Concatenate and minify dependencies for enqueued JavaScript files
- Adding jquery and thickbox to WordPress theme
- jQuery UI Datepicker not working
- Draggable item in custom gutenberg block
- Best Way to Include Scripts on a Specific Template Page
- How to include jquery validate in a template
- Unable to run jQuery script in my template file
- Enqueue jQuery in WordPress
- WordPress Script Loading/Unloading — wp_deregister_script(‘jquery’)
- Enqueuing Script in functions.php vs on the page
- Simple jQuery Click Not Working, though console log recognizes the function [closed]
- How to add unique image class to WordPress
- Dropzonejs with WPCF7 [closed]
- wp_ajax() question.. not using wp_enqueue_script?
- Jquery conflict
- Why isn’t jQuery 2.1 loading in the header?
- enqueue the scripts
- WordPress loads Jquery Automatically – is my idea correct to add it to the footer?
- Problem in loading javascript in footer
- wpColorPicker: How update colors on input value update?
- Enqueue WordPress jQuery after it’s been deregistered by a plugin
- How to embed JS data viz in a simple WordPress website
- WooCommerce Ajax Cart Update Stopped Working
- Rhyzz Repeatable-fields javascript in php and wordpress
- how to en-queue jQuery to load before the tag
- Enque Javascript in Footer?
- Plugins loading multiple copies of JQuery
- Cannot enqueue jQuery correctly using Google CDN
- window.onload wont execute in wordpress
- How to return multiple arguments from AJAX callback function
- JS news ticker is not working on home page but working on other pages. How to solve this?
- How register library to use jquery correct
- WP Customizer compare and set a value via javascript
- “JQMIGRATE: Migrate is Installed” How do I find the problem code? [duplicate]
- Referrer URL with jQuery or Javascript – Cache & Referrer URL Issue
- Using Foundation 5 in WordPress Administration Area
- Ajax Validation for reCaptcha
- Using jquery and javascript in WordPress
- Can’t delete the default jQuery in the theme
- oEmbed Video in Modal
- AJAX Success Function using JS substr() fails in WP 4.1 vs 4.0
- How to add external remote JS source to Gravity Forms?
- Calling multiple scripts using wp_enqueue_script
- Show and hide element when URL contains certain section of text?
- Defer Parsing of Scripts
- Orderby post__in Not Working Correctly?
- jQuery Plugin Uncaught TypeError: jQuery(…).slider is not a function
- Notify user we would like them to clear their cookie. Provide a working button to clear cookies for user
- Call full image url instead of stylsheet directory url in JS for Infinite Scroll Function
- comment-reply.js disables any other form javascript
- File not enqueueing
- Enqueue script, taking no effect [closed]
- How to blur the_post_thumbnail() via blur.js (jquery)?
- Custom Javascript not working? [closed]
- Displaying contents of a tab
- How to deregister scripts all at once
- Object [object Object] has no method ‘slides’
- Add jQuery function to media button
- TypeError: $ is not a function Error using parallax effect in WordPress Template [duplicate]
- jQuery append only works if I select html in admin section [closed]
- Javascript Loading Effect to URLs
- Use WordPress Built In Jquery
- shortcode execution when the page is opened
- Sending jQuery variable to php function
- How to enqueue script before jQuery? [duplicate]
- javascript and css not loading properly in WordPress site
- Making the Google Maps API non readable