Home > Enterprise >  Wordpress function.php wp_enqueue_script doesn't work
Wordpress function.php wp_enqueue_script doesn't work

Time:10-13

I'm trying to integrate jquery into my wordpress theme. I have integrated this code into my function.php but it doesn't work. Can anyone see the problem? Thanks.

//Enqueue Child Styles & Scripts on the Front-End
add_action('wp_enqueue_scripts', function(){
    wp_enqueue_style('nebula-child'); //Stylesheets
    wp_enqueue_script('nebula-main'); //Scripts
    wp_enqueue_script( 'custom', get_stylesheet_directory_uri() . '/assets/js/custom.js', array ( 'jquery', '3.3.2'), '', true);
}, 327);

My custom.js file:

jQuery(document).ready(function($){
    console.log( "ready!" );
});

CodePudding user response:

Your Enqueue is wrong. Your enqueue script says that a script named 3.3.2 is a dependency and won't load your script unless it finds a script by that handle.

wp_enqueue_script( 'custom', get_stylesheet_directory_uri() . '/assets/js/custom.js', array ( 'jquery'), '3.3.2', true);

3.3.2 would be YOUR script version, if your intention is to use the jQuery version... don't.

wp_enqueue_script( string $handle, string $src = '', string[] $deps = array(), string|bool|null $ver = false, bool $in_footer = false )

  • Related