If you want to use the variables from the admin.js script, and you want to be sure it works you have to
- use as handle for
wp_localize_script
the handle of the script that have to use data -
call
wp_localize_script
after that script is enqueuedwp_enqueue_script( 'some_handle' ); wp_enqueue_script("admin", $adminDir."js/admin.js", false, "1.0"); $translation_array = array( 'some_string' => __( 'Some string to translate' ), 'a_value' => '10' ); wp_localize_script( 'admin', 'object_name', $translation_array );
Using the code above and console.log(object_name.some_string);
you will see the translated string on your console.
Read more on wp_localize_script
on Codex.
Related Posts:
- Multiple wp_localize_script
- Do I need to escape data passed to wp_localize_script()?
- wp_localized_script is not defined when called via jquey ajax
- Use wp_localize_script for non existing script
- How do you pass a boolean value to wp_localize_script [duplicate]
- Pass multiple PHP variables to JS in Options Page
- How to get the post ID when creating JS variables with localize_script
- Localization of JavaScript which is only used in one page
- Find out if enqueued script uses wp_localize_script?
- Using wp_localize_scripts
- wp_localize_script no longer working after 5.5 update
- How can I get variable from php function and use it in wp_localize_script?
- wp localize script is not working in a custom AJAX request
- Using template tags in external JS file
- Issue with wp_localize_script
- Translate string with wp_localize_script()
- What about Deferring a localized script?
- help with wp_localize_script
- Is there a way to know the name of all variables passed by wp_localize_script?
- How to define variables in WordPress AJAX?
- Is it possible to use wp_localize_script to create global JS variables without a specific script handle?
- How to intercept already localized scripts
- What is the correct way to build a widget using OOP
- Creating Multiple wp_localize_script for Shortcode?
- w3 total cache minification breaks wp_localize_script() [closed]
- wp_localize_script with boolean and init
- wp_localize_script $handle
- enqueue and localize script in footer
- How to add extra attributes to the script tag added via wp_localize_script()
- Localize variable for multiple Shortcodes
- jQuery Autocomplete not working with wp_localize_script
- Problem in wp_localize_script
- How to localize value of posts
- How to overwrite JS variable with wp_localize _script?
- Setting HTML properties in a Gutenberg plugin using WordPress settings
- Can not pass the value of google pie chart from custom meta box
- Nonces, AJAX, script variables & security in WordPress
- Remove type attribute from script added by wp_localize_script
- Wp_localize_script from Shortcode [closed]
- Ajaxing in functions.php
- Does wp_localize_script call a Javascript Function or Simply Pass PHP Parameters to It
- wp_localize_script and host/browser cache
- esc_html__ security : what for in this example?
- Can wp_localize_script be used within a shortcode?
- wp_add_inline_script not adding when script_loader_tag filtered
- How can I output a php value into a JS file within WordPress?
- how to send Ajax request in wordpress backend
- Different uniqid when calld in wp_localize_script and shortcode
- Using wp_localize_script inside template page to transfer var from php to js
- Script Localization doesn’t work
- WordPress Ajax problem with undefined url
- How to localize admin.php only once
- Enqueue scripts all over but not in single.php
- Admin-Ajax Error
- Localizing script to pass a value to a javascript function
- Path to image in js with wp_localize_script [closed]
- adding custom script to functions file
- Why is wp_localize_script returning false?
- Ajax call with javascript in post content (not enqueued)
- Update Data parameter of a wp_localize_script() call
- Set TRUE or FALSE based on a wp_localize_script option value
- Problem passing id-specific objects to javascript via wp_localize_script
- How to add ajax url to js using wp_add_inline_script()?
- Using wp_localize_script to get data from cpt and pass it to maplace-js locations
- Can’t access PHP array inside script localization from javascript
- in jquery read a multidimensional array via wp_localize_script()
- Localizing methods for jQuery append prepend wrap parent
- How can I get user data into a javascript object?
- issue in wp_localize_script
- Localize script not working in ajax
- wp_localize_script() and JavaScript namespaces
- WordPress Ajax Filter
- wp_localize_script not passing the data
- Getting a variable inside foreach from PHP to JS after localization
- Use options to control jQuery plugin
- How to localize data array in plugin’s option page
- How to load dynamic option with ajax
- Getting jQuery AJAX to work in WordPress (getting -1)
- Parsing post->ID in included plugin file
- wp_enqueue_script calling jQuery at different times for different browsers?
- Get localize of a loaded javascript
- localize_script but data changes dependent on product ID
- How to Object.freeze wp_localize_script
- Get with jQuery the value of an ACF field
- localize_script or rest api
- I can’t load my images from a js file using wp_localize_script
- bundled jquery in theme js not working with wp_localize_script
- Frontend AJAX Request causes Error: ‘Call to undefined function add_action’
- wp localize script makes variable global, how to solve that?
- Multiple shortcodes only use attributes from one of the shortcodes on custom plugin
- How to make sure, that only the selected post is changing?
- How to get, in WP page’s script, a wp enqueued script (in Functions.php)?
- Using wp_localize_script in template file – is it secure?
- Pass max posts to Javascript
- Pass list of categories to JS
- wp_localize_script not create variable in head section
- Passing widget options to external script
- Using WP Ajax and jQuery to process multiple forms on the same page?
- WordPress wp_localize_script nonce and ajax URL
- Import js variables loaded via wp_localize_script() into js module without global scope connection