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

learn more… | top users | synonyms

0
votes
1answer
58 views

Ajax call with javascript in post content (not enqueued)

I would like to make an Ajax call within a JS which I do not wish to enqueue for the whole website. To do that, I put the script directly at the end of the post for which it is relevant rather than ...
4
votes
1answer
41 views

Do I need to escape data passed to wp_localize_script()?

Title pretty much says it all. I took a look at the source, and I didn't see any escaping being done. But, I can't say for sure. wp_localize_script( 'script-hook', 'object_name', array( 'param_1' ...
1
vote
1answer
55 views

WordPress Ajax problem with undefined url

I have problem with wordpress plugin - in jQuery.ajax part, the ajax_object (url: ajax_object.ajax_url) is undefined and I don't know why. I cant recieve correct code from my php plugin, but if I ...
0
votes
0answers
41 views

How to implement wp_localize_script with add_menu_page

I have a class Namer and this class adds a menu page (add_menu_page) and this in turn loads CSS and javscript, but I can't seem to load the wp_localize_script to do AJAX calls & Nonce, here is my ...
1
vote
1answer
54 views

How can I output a php value into a JS file within Wordpress?

I am trying to use get_theme_mod option from php to load into my js file. I've used wp_localize_script to convert. The tweet_id is where I need to place the $tweet value outputted. Any help would ...
0
votes
0answers
31 views

Using wp_localize_script to output info from anchor text

I’m venturing into unfamiliar territory using a WordPress script that collects user data and saves it to the database, allowing administrator to access and manipulate that info. I need such because ...
0
votes
1answer
72 views

Add action hook into wp_localize_script

Is it possible to add an action hook via wp_localize_script, so I can position where I want the hook to run in HTML markup that is made in the JavaScript? So something like: $data = array ( ...
0
votes
1answer
87 views

Is there a better way to access transients using javascript

I've been searching around the web trying to find a better way to use wordpress transients with javascript. Currently I am using admin-ajax to run a php function that retrieves the transient and ...
0
votes
1answer
32 views

help with wp_localize_script

I am a little confused on this function. I have it working for one javascript variable. I tried to get it working for two others and it found that it repeats the code in the header 3 times. I tried ...
0
votes
0answers
30 views

Getting Menu Items Parameters in Javascript Loop

I'm using the Menu Image Plugin - https://wordpress.org/plugins/menu-image/ It adds a image to the menu I need to extract or output the menu items ie Name, Menu-Url, Menu-image into javascript loop, ...
0
votes
1answer
38 views

Problem in wp_localize_script

I am try to enque and localize my word-press scripts My code for for enque my scripts is function load_my_scripts() { wp_register_script('custom-js', get_stylesheet_directory_uri() . ...
0
votes
1answer
109 views

Update Data parameter of a wp_localize_script() call

I'm working on a child theme, In my-page-template.php I have : //... $current_key= 5; //calculated result wp_localize_script('my_js', 'ajaxload', array('post_id' => $current_key)); In my_js.js ...
0
votes
2answers
275 views

Passing variable data from external jQuery file to options.php

I'm setting up a plugin that requires passing of a variable from a stand alone jQuery file to options.php. I have (I think) set up the scripts to be used in my plugin file like so: function ...
0
votes
0answers
175 views

Ajax request not working on firefox

myscript.js jQuery(document).ready( function ($j) { $j('#button').on('click', function () { var data = { action: 'time', type: "POST", time_var: 'day', ...
0
votes
2answers
127 views

Localizing script to pass a value to a javascript function

i'm really getting crazy about this. after hours of trials, i can't get out of this. I'm trying to pass a php variable value to an enqueued jquery script but i can't. here is my code. php : ...
0
votes
0answers
53 views

Global Navigation for Multi-site Sub-sites Using jQuery

I'm looking to add the main site's main menu to the top of all sub-sites on a multi-site install. Requirements The menu should appear directly after body, above any site content, independent of ...
1
vote
0answers
38 views

how to localized scripts of new page requested by ajax?

I'm using ajax to load pages in WP ( all links of my theme works with ajax) and when i go from a page to another, I remove old script tag ( current page ) and add scripts of requested page ...
0
votes
1answer
155 views

Is there a way to know the name of all variables passed by wp_localize_script?

I am using wp_localize_script to pass values to a jquery script. Sometimes this might happen several times on the same page, which means I need to set a different variable name to each ...
1
vote
0answers
116 views

How to overwrite JS variable with wp_localize _script?

The function wp_localize_script( $handle, $name, $data ); does not work when trying to overwrite the same variable, that is when calling the function second time with the same $handle and $name but ...
0
votes
1answer
297 views

How do you pass a boolean value to wp_localize_script [duplicate]

What is the best way to pass a boolean into wp_localize_script as from what I can see everything is interpretted as strings. I have a backend user options form for a plugin, when the values are ...
0
votes
1answer
317 views

Passing PHP Variables to JS using Localize Script

Im trying to pass some variables (author of the post, category of the post, and title of the post) to a js file using wp_localize_script. I cannot, for the life of me get these correct. How can I ...
0
votes
0answers
113 views

Using wp_localize_script on serialized array in get_options

I am trying to use wp_localize_script in a plugin on a serialized array from a stored get_options value function ng_slicknav_scripts_styles() { wp_register_script ( 'slickjs' , plugins_url( ...
0
votes
0answers
63 views

pass from my php code a value to my jquery file

I want to pass from my php code a value to my jquery file(both in a plugin code). I managed to do it with simple variables with wp_localize_script() but I'm stack with passing class value(that should ...
0
votes
0answers
96 views

Pass max posts to Javascript

I'm doing a fairly standard situation where posts are loaded with AJAX via a list. I'm having difficulty passing from WP/PHP to JS when the max posts are reached. Here's what I use to enqueue assets ...
0
votes
1answer
868 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 ...
4
votes
1answer
423 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 ...
3
votes
2answers
386 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 ...
0
votes
1answer
354 views

How to get $post object available inside functions.php to localize script?

I have a problem with a wp_localize_script in my functions.php file. I am trying to get a script localized for a custom post type ("gallery"), however, the error emerges that I am trying to access a ...
0
votes
1answer
555 views

Using wp_localize_script to store the template url into a variable to use in JS

I was trying to store the template url (bloginfo(template_url);) into a variable so I could use it in my JavaScript. However, I realized this wasn't possible and someone alerted me to ...
0
votes
1answer
215 views

Calling wp_localize_script in a different function

I am trying to localize a variable in a javascript below.. The scenario is that I want to dynamically get the post_id and localize it in the jquery I have enqueued through wp_enqueue_scripts. Here's ...
7
votes
4answers
2k views

Is there a JavaScript API? How to access public and private data in JS?

According to this post there is no built-in JavaScript API for Wordpress. Therefore developers who want to build on AJAX seem to come up all with their own solution which doesn't seem right to me. ...
0
votes
2answers
539 views

Set TRUE or FALSE based on a wp_localize_script option value

I am trying to pass a variable value to my JS file using wp_localize_script and setting a function's one of the options to either true or false. Despite of all my efforts, its not working. Here is ...
2
votes
1answer
231 views

Can not pass the value of google pie chart from custom meta box

I am trying to build a google pie chart in my wordpress site based on user input . Hence I have created custom meta box , and use wp_localize_script . Here is what I have done to pass custom metabox ...
0
votes
1answer
233 views

localizing variable on front-page.php template fails but succeeds on single page and taxonomy archive

I have the following code in a php include file: function pass_the_var() { $video_embed_code = jkaw_oembed_code(); return array( 'embedCode' => $video_embed_code ); } ...
0
votes
2answers
1k 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 ...
0
votes
0answers
104 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 ...
0
votes
2answers
989 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 ...
3
votes
2answers
1k 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 ...
13
votes
3answers
5k 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 ...
0
votes
1answer
85 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 ...
0
votes
1answer
341 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 ...
1
vote
1answer
299 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 : { ...
0
votes
2answers
573 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( ...
0
votes
1answer
476 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) - ( ...
1
vote
1answer
4k 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 ...
1
vote
2answers
624 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'); ...
0
votes
1answer
983 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 ...
0
votes
1answer
137 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 ...
0
votes
0answers
158 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 ...
0
votes
1answer
750 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 ...