wp_localize_script does not work
-
I’m working on a custom plugin to use in one of my websites and I’m having trouble with the wp_localize_script word press function, function that I use quite often without problems. i create the following function to
enqueue
the scripts and stylesfunction ar_include_plugin_front_end_files(){
wp_register_script('ar_home_js', plugin_dir_url( DIR ) . 'public/js/ar-home.js' , array('jquery') , '1.0.0' , true );
wp_register_style('ar_promo_style', plugin_dir_url( DIR ) . 'public/css/ar-promo.css' );
wp_localize_script( 'ar_front_functions_js', 'ar_var' ,array(
'ajaxUrl' => admin_url('admin-ajax.php'),
'nonce' => wp_create_nonce( 'wp_rest' )
)
);
wp_enqueue_style('ar_promo_style');
if( is_front_page() || is_home() ){
wp_enqueue_script('ar_home_js');
}
}
add_action( 'wp_enqueue_scripts', 'ar_include_plugin_front_end_files' );the fwo files that I enquee are ok the get inserted in the page code, while wp_localize_scrip that should set some variables in the page code to call in javascript just ddo nothing. No erreor no variable just like it doesn’t exists.
I use the exat same type of code with differnt name in the admin panel and it works just fine.
Any idea?
Viewing 7 replies - 1 through 7 (of 7 total)
Viewing 7 replies - 1 through 7 (of 7 total)
- You must be logged in to reply to this topic.