I wrote a function to load script and stylesheet for a WordPress theme but i guess is not working properly. The stylesheets are being loaded but i can’t get the js to be loaded. Any clue of what I’ve missed here?
function kakadu_setup(){
wp_enqueue_style('style', get_stylesheet_uri(), NULL, microtime(), 'all');
wp_enqueue_style('google-fonts', '//fonts.googleapis.com/css2?family=Source+Sans+Pro:ital,wght@0,400;0,600;0,700;0,900;1,400;1,600;1,700;1,900&display=swap');
wp_enqueue_style('andmars', get_theme_file_uri( '/css/andmars.css' ), NULL, microtime(), 'all');
wp_enqueue_style('custom', get_theme_file_uri( '/css/custom.css' ), NULL, microtime(), 'all');
wp_enqueue_script('scripts', get_theme_file_uri( '/js/scripts.js' ), NULL, microtime(), true);
}
add_action( 'wp_enqueue_scripts', 'kakadu_setup');
Any help would be great!
Thanks
3
Answers
The 3rd parameter of wp_enqueue_script() would be an array() of dependency, not the NULL value.
Try this:
As Aman Mehra suggested, I would not fill in NULL. Also, the name "scripts" and the microtime() function doesn’t look right.
If you read the WordPress developers handbook, you can see the args:
wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer );
So maybe try:
wp_enqueue_script(‘kakadu-scripts’, get_theme_file_uri( ‘/js/scripts.js’ ), ”,”, true);
If that still doesn’t work, the issue is somewhere else and you’ll have to give more information.
}
add_action( ‘wp_enqueue_scripts’, ‘kakadu_setup’ );