Last active
March 10, 2021 19:21
-
-
Save doxt3r/c4b4ae037ab14c4430e25c205ca0f98e to your computer and use it in GitHub Desktop.
Pass php variables to enqueued js 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
/* Custom script with no dependencies, enqueued in the header */ | |
add_action('wp_enqueue_scripts', 'reem_enqueue_custom_js'); | |
function reem_enqueue_custom_js() { | |
$loggedIn = (int) is_user_logged_in(); | |
$locale = get_locale(); | |
wp_enqueue_script('custom', get_stylesheet_directory_uri().'/js/custom.js'); | |
wp_localize_script('custom', 'custom_vars', array( | |
'loggedIn' => $loggedIn, | |
'locale' => $locale, | |
'siteUrl' => site_url() | |
) | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
custom.js code: