• I am using a theme which has lots of custom widgets in a widgets.php file. I need to use jQuery and a custom script for 2 of these widgets which will load on the home page.

    I have wp_enqueue_script('jquery'); on the header.php file before the wp_head function. And I am adding the custom script below the wp_head function. However, nothing works when I load the page. If I place the jquery file and the custom script inside each or both the widgets, it works on the first widget but not on the second one. Can some one please tell me how to get this working?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter blaumond

    (@blaumond)

    Thanks for the support!

    remove all that from header php and add this to functions.php

    function blmd_load_scripts() {
            wp_enqueue_script( 'custom-script', '/path_to/your_script.js', array( 'jquery'), false);
    }
    
    add_action( 'wp_enqueue_scripts', 'blmd_load_scripts' );

    This is using the wp_enque_script() and telling it your script depends on jquery. WordPress will make sure jQuery is properly loaded along with your custom script. (Unless your theme or another plugin is altering something)

    Your welcome for the free support !

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘jQuery and Custom Script not loading’ is closed to new replies.