Created
September 11, 2020 04:35
-
-
Save naumanahmad17/8cc85c78e6c7a08aa6cbaf0d42babaff to your computer and use it in GitHub Desktop.
Localize PHP Variables to JavaScript
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
function set_js_vars() { | |
wp_register_script( 'jsVars', ''); | |
wp_localize_script( 'jsVars', 'page_urls', array( | |
'ajaxUrl' => admin_url( 'admin-ajax.php' ), | |
'homeURL' => get_home_url(), | |
'templateDir' => get_template_directory_uri(), | |
) ); | |
wp_enqueue_script( 'jsVars' ); | |
} | |
add_action( 'wp_enqueue_scripts', 'set_js_vars' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment