Added in my child's theme JavaScript File:


What's wrong?

  • 1
    $ is probably not defined (in the global/parent scope), so try using jQuery(function( $ ) instead. But that is a JS thing not specific to WordPress.
    – Sally CJ
    Feb 21, 2021 at 19:07
  • @SallyCJ Not working. Global scope? The jQuery library is loaded in head provided by WordPress. Feb 21, 2021 at 23:00
  • Global scope means window.$ - try via the browser's console, type window.$ - does it show that the variable is a function? If yes, then it probably means you used the wrong selector - is there an element on the page with the CSS class copyright? If yes, then perhaps by the time your code is run, the element is not yet in the DOM... try alert( $( '.copyright' ).length ) in your code to confirm the element is actually already there. But still, all that is a generic JS/jQuery thing - that could happen everywhere, hence not specific to WordPress..
    – Sally CJ
    Feb 22, 2021 at 6:06
  • @SallyCJ My error was "$()" not defined like you said before. So, put my code in another file and enqueued the script. It seems there was a conflict with another jQuery library.Something with $.noConflict() maybe. I really can't fully explain it. Here is what my question should have been: stackoverflow.com/questions/2194992/jquery-is-not-defined?rq=1 Other Reference: mkyong.com/jquery/jquery-is-not-working-in-wordpress-solution Feb 22, 2021 at 18:28
  • 1
    @SallyCJ jQuery(function( $ ) acts as a failsafe if you have other JS libraries. I'm guessing according to: jQuery . Thanks for that. Feb 22, 2021 at 18:43


Browse other questions tagged or ask your own question.