Created
April 15, 2015 19:13
-
-
Save atsea/1ae6f18af71756171445 to your computer and use it in GitHub Desktop.
WordPress: add php to js with wp_localize_script
This file contains hidden or 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
/** | |
* Move JS to Bottom of Footer | |
* http://www.wpbeginner.com/wp-tutorials/how-to-move-javascripts-to-the-bottom-or-footer-in-wordpress/ | |
*/ | |
/* | |
* Use wp_localize_script to load php into js | |
* https://pippinsplugins.com/use-wp_localize_script-it-is-awesome/ | |
*/ | |
function ud_footer_js() { | |
wp_enqueue_script('footer-script', plugins_url('include/www/modules/seal-blueheader-fluid/js/script.js' , __FILE__ ),'','1.2',true); | |
wp_localize_script('footer-script', 'pw_script_vars', array( | |
// 'alert' => __('Hey! You have clicked the button!', 'pippin'), | |
// 'message' => __('You have clicked the other button. Good job!', 'pippin') | |
'sites_url' => __(esc_url( home_url( '/' ) ), 'Divi'), | |
'ud_url' => __('http://gsa1.udel.edu/search', 'Divi') | |
) | |
); | |
} | |
add_action('wp_enqueue_scripts', 'ud_footer_js'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment