Created
January 3, 2019 16:15
-
-
Save kostasx/b0d36b18625ec45c1a555e4fdc32bef7 to your computer and use it in GitHub Desktop.
WordPress Localized Scripts: Pass PHP data to JavaScript - The PHP code.
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
<?php | |
// Place this code in your child theme's functions.php file | |
function myprefix_enqueue_scripts() { | |
wp_enqueue_script( | |
'custom-script', | |
get_stylesheet_directory_uri() . '/js/custom.js' | |
); | |
wp_localize_script( 'custom-script', 'php_data', array( | |
'message' => __('A message that can be translated!' ) | |
) | |
); | |
} | |
add_action('wp_enqueue_scripts', 'myprefix_enqueue_scripts'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment