Title: Please use wp_localize_script
Last modified: August 21, 2016

---

# Please use wp_localize_script

 *  [Chris Wiegman](https://wordpress.org/support/users/chriswiegman/)
 * (@chriswiegman)
 * [12 years ago](https://wordpress.org/support/topic/please-use-wp_localize_script/)
 * Please consider [wp_localize_script](http://codex.wordpress.org/Function_Reference/wp_localize_script)
   for adding script variables. Just echoing a script tag can cause issues with 
   plugins and themes.
 * [https://wordpress.org/plugins/gravity-forms-placeholder-support-add-on/](https://wordpress.org/plugins/gravity-forms-placeholder-support-add-on/)

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [silb3r](https://wordpress.org/support/users/silb3r/)
 * (@silb3r)
 * [11 years, 12 months ago](https://wordpress.org/support/topic/please-use-wp_localize_script/#post-4701273)
 * Agreed, this would make for a much cleaner plugin. There’s not reason JavaScript
   and PHP can’t *work* together, they just shouldn’t *live* together.
 *  Plugin Author [phpmypython](https://wordpress.org/support/users/phpmypython/)
 * (@phpmypython)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/please-use-wp_localize_script/#post-4701275)
 * Since the plugin takes the labels generated by Gravity forms and then uses those
   as the placeholder values there shouldn’t be a reason for me to have to localize
   the script for translation.
 *  [Josh Levinson](https://wordpress.org/support/users/joshlevinson/)
 * (@joshlevinson)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/please-use-wp_localize_script/#post-4701276)
 * [@phpmypython](https://wordpress.org/support/users/phpmypython/) – He didn’t 
   mean for localization. He meant for actually defining the variables you need 
   in javascript. That’s the other (purposed) reason of wp_localize_script.
 * In other words, in gravityform-placeholder-addon.php:
 *     ```
       add_action('wp_enqueue_scripts', 'gf_placeholder_addon_script_enqueue');
   
       function gf_placeholder_addon_script_enqueue() {
       	$placeholder_js = plugins_url( basename(dirname(__FILE__)) ).'"/jquery.placeholder-1.0.1.js';
       	wp_enqueue_script('gf_placeholder_add_on', $plugin_url . '/gfplaceholderaddon.js', array('jquery'), '1.0' );
       	wp_localize_script('gf_placeholder_add_on', 'gf_placeholder_vars', array('jquery_placeholder_url' => $placeholder_js) );
       }
       ```
   
 * In your gfplaceholderaddon.js:
 *     ```
       if ( support && gf_placeholder_vars.jquery_placeholder_url )
       		$.ajax({
       			cache: true,
       			dataType: 'script',
       			url: gf_placeholder_vars.jquery_placeholder_url,
       			success: function() {
       				$('input[placeholder], textarea[placeholder]').placeholder({
       					blankSubmit: true
       				});
       			},
       			type: 'get'
       		});
       ```
   
 * I made a couple of edits after my initial post, so make sure you don’t rely on
   the initial notification of my post for accurate advice.
 *  Plugin Author [phpmypython](https://wordpress.org/support/users/phpmypython/)
 * (@phpmypython)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/please-use-wp_localize_script/#post-4701280)
 * I’m working on incorporating this i assure you i haven’t forgot im just bogged
   down on other projects. i appreciate your suggestion and it will be implemented
   as soon as i can get to it.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Please use wp_localize_script’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/gravity-forms-placeholder-support-
   add-on.svg)
 * [Gravity Forms Placeholder Add-On](https://wordpress.org/plugins/gravity-forms-placeholder-support-add-on/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/gravity-forms-placeholder-support-add-on/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/gravity-forms-placeholder-support-add-on/)
 * [Active Topics](https://wordpress.org/support/plugin/gravity-forms-placeholder-support-add-on/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/gravity-forms-placeholder-support-add-on/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/gravity-forms-placeholder-support-add-on/reviews/)

 * 4 replies
 * 4 participants
 * Last reply from: [phpmypython](https://wordpress.org/support/users/phpmypython/)
 * Last activity: [11 years, 11 months ago](https://wordpress.org/support/topic/please-use-wp_localize_script/#post-4701280)
 * Status: not a support question