• Mike

    (@maltesesolutions)


    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)
  • 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

    (@maltesesolutions)

    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.