[wp-trac] [WordPress Trac] #48098: ReferenceError: jQuery is not defined even if it is enqueued
WordPress Trac
noreply at wordpress.org
Sat Sep 21 13:23:00 UTC 2019
#48098: ReferenceError: jQuery is not defined even if it is enqueued
-------------------------------+------------------------------
Reporter: KestutisIT | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Script Loader | Version: 5.2.3
Severity: normal | Resolution:
Keywords: reporter-feedback | Focuses: javascript
-------------------------------+------------------------------
Changes (by SergeyBiryukov):
* keywords: needs-patch => reporter-feedback
* severity: major => normal
Comment:
Replying to [ticket:48098 KestutisIT]:
> So I have a template in a plugin with:
>
> {{{#!php
> <?php
> // Scripts
> wp_enqueue_script('jquery');
> ?>
> <div class="great-plugin-wrapper">
> <!--- BUNCH OF HTML -->
> </div>
> <script type="text/javascript">
> jQuery(document).ready(function() {
> jQuery('.responsive-deals-slider').slick({
> // Bunch of javascript
> });
> });
> </script>
> }}}
Thanks for the report! When exactly this code runs?
If it's not hooked to the `wp_enqueue_scripts` action as
[https://developer.wordpress.org/reference/functions/wp_enqueue_script
/#more-information recommended in the documentation], then it's too late
for jQuery to be printed in `wp_head()`, so it's only printed in
`wp_footer()`.
> And I'm getting 'ReferenceError: jQuery is not defined' error in console
even if it is enqueued in HTML before using.
> In source code it says jQuery is loaded late in footer
Note that `wp_enqueue_script( 'jquery' )` does not print the script right
away, it only enqueues the script to be printed later by
`wp_print_head_scripts()` or `wp_print_footer_scripts()`.
> Does something changed in WordPress in recent months regarding this, and
why so? It was working at least 6 months ago.
As far as I know, nothing has changed in the script loader in the last few
years in that regard.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/48098#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list