Last active
January 3, 2020 20:00
-
-
Save vanaf1979/20ffe98a7ec8b454f7fad69edd88e865 to your computer and use it in GitHub Desktop.
Add a action to enqueue stylesGist for my "WorpdPress: Css Styles and Javascripts in theme development (In depth)" article: https://since1979.dev/wordpress-css-styles-and-javascripts-in-theme-development-in-depth/
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 | |
function my_theme_enqueue_scripts() | |
{ | |
wp_deregister_script('jquery'); | |
/* Pass sata from php to javascript */ | |
wp_register_script( 'my-theme-scripts', get_template_directory_uri() . '/public/js/app.js', array(), '1.0.0', true ); | |
$data_array = array( | |
'some_string' => __( 'Some string to translate', 'textdomain' ), | |
'themepath' => get_template_directory_uri() | |
); | |
wp_localize_script( 'my-theme-scripts', 'object_name', $data_array ); | |
wp_enqueue_script( 'my-theme-scripts' ); | |
} | |
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_scripts' ); | |
?> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment