Menü schliessen
Created: February 25th 2021
Last updated: December 10th 2021
Categories: IT Support,  JavaScript Development,  Wordpress
Author: Tim Fürer

WordPress: jQuery is not working

Tags:  guide,  Javascript,  jQuery,  wordpress

Is your jQuery inside WordPress not working even though the code appears to be correct?

If you are using the '$' shortcut to call the jQuery function, try using 'jQuery' instead.

So:

$(function() {
	console.log( "Hello World" );
});

becomes:

jQuery(function() {
	console.log( "Hello World" );
});

But why is this happening in WordPress?

WordPress uses its own jQuery version and runs it in compability mode. This ensures that there are no problems with other JavaScript Libraries using '$' as a shortcut to call them.

If you want jQuery to use '$' again, add this at the beginning of your code.

$ = jQuery.noConflict();

In fact, you could use pretty much anything as your shortcut to jQuery. Instead of '$', perhaps you want to use 'j' or something else.

Read more about 'jQuery.noConflict()' on the jQuery Documentation if you want to get an even better understanding.