0

I've been trying to figure out why my jQuery isn't properly working with my custom Wordpress website?

Here's my functions.php file

<?php 

    function customcode_theme_styles() {
        wp_enqueue_style('customcode-css', get_template_directory_uri() . '/style.css');
    }
    add_action ('wp_enqueue_scripts', 'customcode_theme_styles');

    function customcode_theme_js() {
        wp_enqueue_script('easing-js', get_template_directory_uri() . '/js/jquery.easing.1.3.js', array('jquery'));
        wp_enqueue_script('animate-enhanced-js', get_template_directory_uri() . '/js/jquery.animate-enhanced.min.js', array('jquery'));
        wp_enqueue_script('superslides-js', get_template_directory_uri() . '/js/jquery.superslides.min.js', array('jquery'));
        wp_enqueue_script('customcode-js', get_template_directory_uri() . '/js/customcode.js', array('jquery'));
    }
    add_action ('wp_enqueue_scripts', 'customcode_theme_js');

?>

Now I am able link my CSS perfectly fine, but anything jQuery isn't properly linking?

Here's the customcode.js file I am trying to link my functions.php to:

$(window).scroll(function() {
          if ($(document).scrollTop() > 50) {
            $('.navbar').addClass('nav-scroll');
          } else {
            $('.navbar').removeClass('nav-scroll');
          }
});

Am I missing something? Let me know, any help is much appreciated thanks!

omgummy
  • 49
  • 9
  • 1
    so what happens? Is file loading? Errors in console? Likely get `$ not defined` error since wordpress generally uses `noConflict()` – charlietfl Jan 18 '16 at 19:24
  • Your browser console will tell you exactly what the issue is. You'll be able to see that `$` is undefined, and that your scripts are loading correctly. – rnevius Jan 18 '16 at 19:38
  • Don't need to assume ...look for it in browser dev tools network and look for errors also in console – charlietfl Jan 18 '16 at 19:38
  • I receive this: Uncaught TypeError: $ is not a function – omgummy Jan 18 '16 at 19:39
  • Thanks to rnevius http://stackoverflow.com/questions/7975093/typeerror-undefined-is-not-a-function-evaluating-document This solved the problem! – omgummy Jan 18 '16 at 19:46
  • So it's something like this? `function CustomFunction() { // Your script }; jQuery(document).ready(function($) { CustomFunction(); }); ` – Jarod Thornton Jan 18 '16 at 19:59

0 Answers0