Skip to main content

Questions tagged [wp-localize-script]

Localizes a script, but only if script has already been added. Can also be used to include arbitrary Javascript data in a page.

Filter by
Sorted by
Tagged with
0 votes
2 answers
2k views

jQuery Autocomplete not working with wp_localize_script

Bit of background: I am building an autocompleting-search box for a list of Trades (a Custom Taxonomy). I asked this question and very helpfully got a much better understanding of how WordPress and ...
Tom Oakley's user avatar
0 votes
0 answers
395 views

Pass list of categories to JS

I'm trying to pass a list of all the categories to my MixItUp settings in my JS file to show all the items on load. But I can't seem to generate a list of the categories and reliably send them over to ...
Picard102's user avatar
  • 933
0 votes
1 answer
111 views

Use options to control jQuery plugin

This may be a dumb question, but I've been teaching myself Wordpress and I've been struggling with this for a while. What I want to do is use a Wordpress control panel page to control a countdown ...
anguiac7's user avatar
  • 103
7 votes
2 answers
5k views

Creating Multiple wp_localize_script for Shortcode?

I have a shortcode that displays recent WooCommerce products in a carousel, however i would like the end user to be able to use the shortcode multiple times on the same page, currently when this ...
Shoebox's user avatar
  • 334
1 vote
1 answer
847 views

Localize variables with TinyMCE script

I am writing a plugin that has variables that I would like to localize for use within TinyMCE. The logical choice seemed to me to localise them with the enqueued TinyMCE script itself like so: public ...
McShaman's user avatar
  • 179
1 vote
1 answer
957 views

Path to image in js with wp_localize_script [closed]

I'm trying to implement animated svg icons into my Wordpress theme. All's is great, except I can't figure out how to put proper url for svg images in this js file: var svgIconConfig = { plus : { ...
Nikita's user avatar
  • 419
2 votes
2 answers
1k views

WP_LOCALIZE_SCRIPT doesn't work

I am creating AJAX loading and need to use WP_LOCALIZE_SCRIPT but cannot make it work. Here is my code. I place it in functions.php wp_enqueue_script( 'page_data'); $gallery_js_data_array = array( ...
user43506's user avatar
0 votes
1 answer
817 views

wp localize script is not working in a custom AJAX request

I am trying to use wp_localize_script() to send some php values to a script. The following are the part of the file inc/show-event.php. if( $price ) { $pricefortwo = ceil( ( 2 * $price) - ( 0....
Maruti Mohanty's user avatar
31 votes
4 answers
20k views

Is it possible to use wp_localize_script to create global JS variables without a specific script handle?

Can we somehow use wp_localize_script() to create global js variables without a specific script handle which can be accessed from all the js files, even if the js scripts are not enqueued properly by ...
Subharanjan's user avatar
  • 1,589
0 votes
2 answers
2k views

How do I pass the template url to javascript in the ADMIN area of my theme?

I need to pass the path to a php file (located in a folder in my theme) to a JS file being used in my admin area but I have no idea how to accomplish that. What Im trying to do, is build a page ...
rugbert's user avatar
  • 178
2 votes
1 answer
21k views

Use of global variables within plugin [closed]

I am creating my first plugin ever and I found my self having to call the same option variables within various parts of the same page therefore I sought for a solution and stumbled upon global ...
David Garcia's user avatar
2 votes
2 answers
1k views

Localize variable for multiple Shortcodes

I have this code for flexslider Shortcode add_shortcode('flexslider', function($atts){ global $post; $ids = explode(',', $atts[ids]); $uniqid = uniqid(); wp_enqueue_script( 'shortcode_flexslider'); ...
Mohamed Badawy's user avatar
0 votes
1 answer
2k views

Problem passing id-specific objects to javascript via wp_localize_script

I'm using wp_localize_script to pass multiple arrays of data into a javascript file. To differentiate between the different arrays (and prevent overwriting), they are labelled relative to the post id ...
Mr. G's user avatar
  • 127
0 votes
1 answer
251 views

How to localize data array in plugin's option page

So i am localizing data saved in an array for my plugin's options, however the data is only localized in the front end, how can I localize data in the plugin's option page as well? The following is ...
David Garcia's user avatar
0 votes
0 answers
218 views

Passing a location-dependent array via wp_localize_script within a shortcode

I have created a shortcode that is intended to be inserted into custom field of a music custom post type. The shortcode is coverted into an audio playlist using the jplayer jquery plugin (and it's ...
Mr. G's user avatar
  • 127
0 votes
1 answer
4k views

in jquery read a multidimensional array via wp_localize_script()

From PHP I am pushing a basic array to jQuery via wp_localize_script() and then using the array data in my script file. Now I have extended the array into a multidimensional array and can not figure ...
Jason's user avatar
  • 606
11 votes
4 answers
5k views

How to intercept already localized scripts

If a plugin uses some script (prominent example: jQuery UI Datepicker), but you're not happy with how the script renders the output, then there're two possibilities: 1. Unregister the script > Add ...
kaiser's user avatar
  • 50.8k
2 votes
0 answers
932 views

Wp_localize_script from Shortcode [closed]

I've been trying for hours and tried several answers from here and Google but still no luck.. need help. I am making a shortcode (slider) and trying to execute a javascript file (for the slider's ...
Mario88's user avatar
  • 53
0 votes
1 answer
304 views

Localizing methods for jQuery append prepend wrap parent

So I am serializing some options in WordPress and then localizing them to be used in my jQuery script, however what I am trying to do next isn't working. jQuery('.advert')+ lu_ban_object.method +('&...
David Garcia's user avatar
0 votes
1 answer
2k views

wp_localize_script not create variable in head section

I try to make an ajax function in wordpress and I enqueued my script and declared my variables like this in functions.php: function my_enqueue_scripts() { wp_enqueue_script( 'load_post', ...
freaky's user avatar
  • 99
8 votes
3 answers
3k views

Passing boolean values with wp_localize_script

I am using wp_localize_script to pass a couple of values from my theme options to a javascript file. First I got the values from my theme options: $options = get_option('theme'); $flex_auto = $...
kath's user avatar
  • 621
0 votes
1 answer
168 views

How to load dynamic option with ajax

Basically I'm creating an options page in which the user will click on a button to display a text input field, which will then be populated by the user with a name. This name will be then saved into ...
WagnerMatosUK's user avatar
0 votes
1 answer
9k views

Can't seem to get wp_localize_script to work

This is my code: wp_enqueue_script('ms_ajax_localized'); wp_localize_script( 'ms_ajax_localized', 'MS_Ajax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'nextNonce' => ...
jackreichert's user avatar
0 votes
1 answer
685 views

Using template tags in external JS file

I’d like to know how to use the get_bloginfo( 'template_directory' ) tag in an external JS file. I just found out that it’s possible using the wp_localize_script function but I didn’t manage to get ...
user1706680's user avatar
0 votes
1 answer
259 views

Passing widget options to external script

I am trying to pass some widget options to an external script using wp_localize_script. I know how to pass the variables and how to use them within the script, but how do I extract the widget options ...
Yoav Kadosh's user avatar
7 votes
2 answers
3k views

What is the correct way to build a widget using OOP

I am working on a simple search form widget, with a built in autocomplete capability (You can download the current version here). The plugin is working, but I am currently rewriting all the code using ...
Yoav Kadosh's user avatar
2 votes
1 answer
3k views

How to localize inline script called with ajax

I have a loop of posts and I allow a user to edit each post using ajax. When the edit button is clicked for the post I use ajax to retrieve the template part containing the edit form for the post. ...
Pollux Khafra's user avatar
1 vote
1 answer
4k views

How to get the post ID when creating JS variables with localize_script

how do you set the current post ID as a JS variable with localize_script? It seems like the $post variable isn't availible in the functions.php file. When is it created? Do i have to add localize ...
John's user avatar
  • 335
3 votes
2 answers
757 views

Nonce best practices: hidden input vs. wp_localize_script?

I noticed while looking at the HTML of an edit page that WordPress uses a lot of hidden input elements for storing nonces. Is there a significant advantage to using either this style of storing ...
Manny Fleurmond's user avatar
0 votes
1 answer
194 views

jQuery dialog prints HTML-Tags under Wordpress

i need some help. I am using wp_localize_script in my Wordpres_Plugin. Inthe documentready-function i use this Code to bring the Message up: $('#button-setup-league').click(function() { $( "#dialog ...
JSS's user avatar
  • 85
3 votes
2 answers
933 views

Use wp_localize_script for non existing script

Task: What I'm trying to do I'm fetching data via the WP Http API from a remote server. The data I'm getting back is JSON encoded. In one of my methods, I'm converting them back and then push it into ...
kaiser's user avatar
  • 50.8k
5 votes
1 answer
1k views

w3 total cache minification breaks wp_localize_script() [closed]

I am trying to configure W3 total cache plugin to speed up my site. The minify option is great but I am running into the following issue: Let's say I have a JavaScript file I am attached wp_localize ...
Roman Epicnerd Sharf's user avatar
0 votes
1 answer
241 views

Parsing post->ID in included plugin file

running into something that has got me completely puzzled. I have a plugin with a main file that looks like this: // Global Variables $mouldings_prefix = 'mouldings_'; $mouldings_name = 'Mouldings'; ...
Zach's user avatar
  • 1,943
1 vote
2 answers
1k views

esc_html__ security : what for in this example?

how does esc_html__ (the 2nd one) protect the $message variable from being hacked ? what's the point to use this protection here (the second one with a plain text)? <?php function unknown(){ ...
Paul's user avatar
  • 319
3 votes
1 answer
3k views

enqueue and localize script in footer

I have a script which must run in my footer, after some variables are declared. It works if I just put the code directly in my footer file, but I think best practices dictate I should do this via ...
Michelle's user avatar
  • 3,458
-1 votes
1 answer
3k views

Using WP Ajax and jQuery to process multiple forms on the same page?

I'm using the following to make ajax calls: wp_enqueue_script( 'my-ajax-request', TAF_PLUGIN_URL . 'js/ajaxcf.js', array( 'jquery' ) ); wp_localize_script( 'my-ajax-request', 'MyAjax', array( '...
Shoebox's user avatar
  • 334
0 votes
2 answers
267 views

adding custom script to functions file

I have a problem adding a custom script to my functions.php file: add_action('wp_print_scripts', 'load_AJAX_URL__'); function load_AJAX_URL__() { wp_localize_script( 'ajax_URL', 'MyAjax', array( '...
greenbandit's user avatar
1 vote
1 answer
263 views

How to localize admin.php only once

I am creating a set of plugins that all use AJAX. Now localizing the admin.php in all the plugins seems to be a bit of an overkill. Is there a way to localize the script only once.\ Now I do not know ...
Saif Bechan's user avatar
7 votes
1 answer
3k views

Multiple wp_localize_script

Is it possible to localize a script more than once? I want to send two separate arrays of params. Or is it only possible to localize a script once, in which case, I'll have to combine the arrays? ...
Laxmidi's user avatar
  • 971
1 vote
1 answer
2k views

Does wp_localize_script call a Javascript Function or Simply Pass PHP Parameters to It

Easy question: I'm trying to understand wp_localize_script. Does wp_localize_script call a JavaScript function or does it simply pass PHP parameters to JavaScript? I want to pass PHP parameters to ...
Laxmidi's user avatar
  • 971
0 votes
2 answers
442 views

wp_enqueue_script calling jQuery at different times for different browsers?

This makes no sense, but in looking at my view source across browsers, wp_localize_script() is inserting tags as expected for all browsers other than IE7,8,9. The script tag is simply not there in ...
Tom Auger's user avatar
  • 7,086
1 vote
1 answer
365 views

Find out if enqueued script uses wp_localize_script?

Is there a function that can check if an enqueued script has a call to wp_localize_script attached to it?
ryanve's user avatar
  • 192
3 votes
3 answers
1k views

wp_localize_script $handle

Can anyone tell me what the "$handle" ( first parameter ) of wp_localize_script is normally used for. Thanks. P.s.: I have no idea why but stackexchange is telling me this question dosen't meet ...
byronyasgur's user avatar
  • 3,032

1 2
3