Adding Custom JS to WordPress? Remember jQuery NoConflict Wrappers

Adding Custom JS to WordPress? Remember jQuery NoConflict Wrappers

If you’re adding some extra jQuery to customize your WordPress site and it doesn’t seem to be working, remember that the copy of jQuery that WP loads is in “no conflict” mode.

If you’re attempting to use the default jQuery shortcut of $, then you’ll want to wrap it with the following:

FREE EBOOK
Your step-by-step roadmap to a profitable web dev business. From landing more clients to scaling like crazy.

By downloading this ebook I consent to occasionally receive emails from WPMU DEV.
We keep your email 100% private and do not spam.

FREE EBOOK
Plan, build, and launch your next WP site without a hitch. Our checklist makes the process easy and repeatable.

By downloading this ebook I consent to occasionally receive emails from WPMU DEV.
We keep your email 100% private and do not spam.

jQuery(document).ready(function($) {
// $() will work as an alias for jQuery() inside of this function
});

This will save you a lot of time beating your head against a wall, wondering why your jQuery isn’t working. ;)

Source: WordPress Codex

Tags: