Title: wp_localize_script
Last modified: September 1, 2016

---

# wp_localize_script

 *  [Mike](https://wordpress.org/support/users/maltesesolutions/)
 * (@maltesesolutions)
 * [9 years, 8 months ago](https://wordpress.org/support/topic/wp_localize_script-1/)
 * I am trying to get my localize script to work however whenever I run the script
   I get the object is not defined.
 * I am updating one of my plugins to ajax and using Tom McFarlin’s Plugin Boiler
   Plate.
 * Here is my php code:
 *     ```
       wp_localize_script('ajax-js', 'ajax_params', array(
   
       			'alert' => __('Hey! You have clicked the button!', 'my-plugin')
   
       		));
       ```
   
 * here is my script:
 *     ```
       jQuery(document).ready(function($){
   
       	$('.someClass').click(function(){
   
       		alert(ajax_params.alert);
   
       	});
   
       });
       ```
   
 * Yet when I click on the button it get the error that ajax_params is not defined.
 * What am I missing.
    Thanks

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

 *  [Jacob Peattie](https://wordpress.org/support/users/jakept/)
 * (@jakept)
 * [9 years, 8 months ago](https://wordpress.org/support/topic/wp_localize_script-1/#post-7638960)
 * The object won’t be created unless you are using `wp_enqueue_script()` for a 
   script named `ajax-js`. Are you loading the script that way?
 *  Thread Starter [Mike](https://wordpress.org/support/users/maltesesolutions/)
 * (@maltesesolutions)
 * [9 years, 8 months ago](https://wordpress.org/support/topic/wp_localize_script-1/#post-7638973)
 * I now see what you are saying.
 * I was not loading the previous script with the same name via wp_enqueue_script().
 * I was using a different name.
    Once I fixed the naming it works like a charm.
   Thanks.

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

The topic ‘wp_localize_script’ is closed to new replies.

## Tags

 * [wp_localize_script](https://wordpress.org/support/topic-tag/wp_localize_script/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 2 replies
 * 2 participants
 * Last reply from: [Mike](https://wordpress.org/support/users/maltesesolutions/)
 * Last activity: [9 years, 8 months ago](https://wordpress.org/support/topic/wp_localize_script-1/#post-7638973)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
