Created
May 12, 2018 03:04
-
-
Save jerrickhakim/5d1feecb73b8179213b36db38eb7c3f9 to your computer and use it in GitHub Desktop.
WordPress Localize Script Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action( 'wp_enqueue_scripts', 'monica_register_js' ); | |
function monica_register_js() { | |
wp_register_script( 'monica-theme-js', get_template_directory_uri() . '/js/monica.js', array( 'jquery' ), '1.0.0', true ); | |
} | |
add_action( 'wp_enqueue_scripts', 'monica_localize' ); | |
function monica_localize() { | |
$slide_out_right_width = 'jkkl'; | |
// Here are the vars that are localized | |
wp_localize_script('monica-theme-js', 'vartransfers', | |
array( | |
'rightwidth' => 'kjkljlkjlk', | |
) | |
); | |
wp_enqueue_script( 'monica-theme-js' ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment