[wp-trac] [WordPress Trac] #48098: ReferenceError: jQuery is not defined even if it is enqueued

WordPress Trac noreply at wordpress.org
Sun Sep 22 05:57:52 UTC 2019


#48098: ReferenceError: jQuery is not defined even if it is enqueued
---------------------------+-------------------------
 Reporter:  KestutisIT     |       Owner:  (none)
     Type:  defect (bug)   |      Status:  closed
 Priority:  normal         |   Milestone:
Component:  Script Loader  |     Version:  5.2.3
 Severity:  normal         |  Resolution:  wontfix
 Keywords:                 |     Focuses:  javascript
---------------------------+-------------------------
Changes (by peterwilsoncc):

 * keywords:  reporter-feedback =>
 * status:  new => closed
 * resolution:   => wontfix
 * milestone:  Awaiting Review =>


Comment:

 Thanks for providing additional information.

 As noted above, the purpose of the `wp_enqueue_scripts()` function is to
 output a script tag in either the header or footer of an HTML document.
 There are other functions to print script tags immediately.

 In your case, the best course of action would be to enqueue jQuery and add
 additional JavaScript to run within wp_footer


 {{{#!php
 <?php
 wp_enqueue_script('jquery');
 add_action( 'wp_footer', function() {
   ?>
   <script>/*javascript here */</script>
   <?php
 }, 11 );
 }}}

 I'm going to close this ticket as wontfix, due the existing functionality
 available and because changing the purpose of the enqueue functionality
 could adversely affect a number of sites.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/48098#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list