Script not working in WordPress fix

Glenn Glenn's Blog 0 Comments

If you have tested a script which works fine within a standard html development file, but for some reason it isn’t working in WordPress then you probably have a compatibility error. Actually the fix is pretty easy… simply wrap / start you code with a jQuery noConflict Wrapper


jQuery(document).ready(function($) {
    // Inside of this function, $() will work as an alias for jQuery()
    // and other libraries also using $ will not be accessible under this shortcut
});

We prefer this approach over adding ‘jQuery’ in the place of every ‘$’ as it enables you to cut and past a code and only change the first line in the document ready function. Otherwise it’s tedious and easy to miss all the ‘$’ within  larger scripts.

Note that many scripts will not run in WordPress without document ready.

About the Author
Script not working in WordPress fix Script not working in WordPress fix 0da77002febbfe28d15144a57bbcc2c9 s 180 d mm r g

Glenn

A highly experienced WordPress Web Developer, Front-end and Back-end Developer & New Media Specialist with extensive knowledge of a wide spectrum of technologies in the Development and Creative Industries built up over a number of years.

Leave a Reply

Your email address will not be published. Required fields are marked *