Support » Fixing WordPress » jQuery script not loading

  • I have set up a child theme for my website based on the WP Bootstrap Starter theme, but there seems to be a problem while loading my javascript file for my jQuery code. Although I have set up wp_enqueue_scripts in my functions.php (http://prntscr.com/nkm8vm), it will not load.

    Alternatively, when I put script tags just above my closing body tag (http://prntscr.com/nkm9ww), my console claims that $ is not a function (http://prntscr.com/nkma5r), which means it loads before the jQuery CDN of the parent theme I assume?

    My website file structure looks like this: http://prntscr.com/nkmaqc

    So what am I overlooking here? Why is my javascript file not loading properly?

    • This topic was modified 6 months, 1 week ago by  El Pablo.

    The page I need help with: [log in to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    Moved to Fixing WordPress, this is not a Developing with WordPress topic. This is a theme specific topic not a developing one.

    Screenshots of code samples are the worst way to ask for support. It doesn’t help you or anyone when you do that. Try sharing the code samples using https://pastebin.com/ instead.

    Which theme is that and where did you download it from? If you can provide that information then it will help get you to the right place.

    WordPress defaults to a jQuery version where usage of $ is not defined. So you need either add that to your script yourself or replace all calls to jQuery functions by changing $(…) to jQuery(…).

    @superkot I have replace the $ by jQuery, but still nothing happens

    @jdembowski The theme I’m using is WP Bootstrap StarterVersie: 3.1.0, which is to be found on the WP Repository.

    My code in functions.php: https://pastebin.com/P2Ew7hmT
    My code in script.js: https://pastebin.com/SeYR8mRB

    Your script is ok if you execute is by pasting in console, so the problem is with enqueueing. Why would you use array(‘javascript’)? Your dependency is jQuery. Anyway, try simplier first:

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

    Hi Superkot, I tried your code but no result. I also tried to paste my jQuery code in the console, but still nothing.

    superkot

    (@superkot)

    You must be doing something wrong. Your code works perfectly fine for me, you just need to enqueue it properly. Copypasting script video: https://cloud.mail.ru/public/2Wjm/5gRDms6xp. Anyway, if you fail to enqueue it as separate file, you can simply add this script to your footer, its not big so it wont affect your site performance.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘jQuery script not loading’ is closed to new replies.