• So I’ve enabled the Google Libraries plugin to help with calling in jQuery, but now I want to upload some JS files that depend on the jQuery library. I created a new folder in the /wp-content/themes folder called scripts and uploaded the two files there.

    Now I have no idea how to properly load them. I want to use them on the entire WP site. I checked the functions.php file for my specific theme to check and see if the Google Libraries plugin was using the wp_enque_script, but couldn’t find anything. Any help would be greatly appreciated!

Viewing 1 replies (of 1 total)
  • Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    For wp_enqueue_script this may work in your functions.php file:

    add_action('wp_enqueue_scripts', 'theme_enqueue_scripts');
    function theme_enqueue_scripts() {
        wp_enqueue_script( 'your-script', get_site_url() . '/wp-content/themes/script/your-script.js', array('jquery') );
    }

    It would be cleaner IMHO if you put that script in the same theme directory as your functions.php file and replace the wp_enqueue_script line with

    wp_enqueue_script( 'your-script', get_template_directory_uri() . '/script/your-script.js', array('jquery') );

    Read more here.

    It’s not my code, I lifted it from some other code I’m admiring for my child theme. ??

Viewing 1 replies (of 1 total)
  • The topic ‘Add some JavaScript files’ is closed to new replies.