| | 3 | |
| | 4 | |
| | 5 | Edit: I know WordPress is using an older version of jQuery for compatibility reasons, but document ready is deprecated as of jQuery 1.8 and removed in jQuery 3.0. See link: [https://api.jquery.com/ready/] |
| | 6 | |
| | 7 | **Before and as of jQuery 3.0 ineffective:** |
| | 8 | {{{ |
| | 9 | $( document ).ready(function() { |
| | 10 | // Handler for .ready() called. |
| | 11 | }); |
| | 12 | }}} |
| | 13 | |
| | 14 | **Which is equivalent to:** |
| | 15 | {{{ |
| | 16 | $(function() { |
| | 17 | // Handler for .ready() called. |
| | 18 | }); |
| | 19 | }}} |
| | 20 | |
| | 21 | Which is problematic for WordPress, when $.noConflict() is used to avoid conflicts the $ shortcut is no longer available. However, we could still pass a reference to the jQuery object. This allows us to use the jQuery object with a dollar sign $, like this: |
| | 22 | |
| | 23 | |
| | 24 | {{{ |
| | 25 | WordPress = jQuery.noConflict(); |
| | 26 | |
| | 27 | WordPress(function( $ ) { |
| | 28 | // Code using $ as usual goes here; the actual jQuery object is jq2 |
| | 29 | }); |
| | 30 | }}} |
| | 31 | |