Make WordPress Core

Opened 14 years ago

Closed 10 years ago

Last modified 9 years ago

#14488 closed defect (bug) (fixed)

wp_enqueue_script in_footer doesn't work on WP known scripts

Reported by: mcr2582's profile mcr2582 Owned by: sorich87's profile sorich87
Milestone: 4.2 Priority: normal
Severity: minor Version: 3.0.1
Component: Script Loader Keywords: has-patch
Focuses: Cc:


I changed some plugin code from:


However, the script was not moved to the footer.

When I looked at the source for wp_enqueue_script, I can see that it's because the check for $in_footer is inside the condition for $src being defined. But built-in scripts don't require a source.

Attachments (2)

14488.diff (616 bytes) - added by sorich87 14 years ago.
14488.patch (650 bytes) - added by SergeyBiryukov 13 years ago.

Download all attachments as: .zip

Change History (17)

#1 @nacin
14 years ago

  • Milestone changed from Awaiting Review to 3.1

14 years ago

#2 @sorich87
14 years ago

  • Cc sorich87@… added
  • Keywords has-patch added; JS footer enqueue removed
  • Owner set to sorich87
  • Status changed from new to accepted

#3 @nacin
14 years ago

  • Milestone changed from 3.1 to Future Release

Don't think is_footer is the right check.

#4 @mitchoyoshitaka
13 years ago

I think is_footer is actually correct there. Would be nice to have this sorted out.

#5 @SergeyBiryukov
13 years ago

Simplified the patch a bit.

#6 @MikeHansenMe
12 years ago

tested and confirmed the patch works.

#7 @MikeHansenMe
12 years ago

  • Cc mdhansen@… added

#8 @valeriosza
11 years ago

I think closing the valid ticket.

#9 @nacin
11 years ago

  • Component changed from General to Script Loader

#10 @wonderboymusic
10 years ago

  • Resolution set to fixed
  • Status changed from accepted to closed

In 31028:

When calling wp_enqueue_script() with a registered $handle, no $src (using the default value, false), and true as the value for $in_footer, ensure that the script actually loads in the footer. If the handle was registered with $in_footer equal to true, this already worked. Make it work for scripts like where $in_footer was initially false, example: wp_enqueue_script( 'json2', false, array(), false, true );

Props SergeyBiryukov.
Fixes #14488.

#11 @wonderboymusic
10 years ago

  • Milestone changed from Future Release to 4.2

#12 follow-up: @sc0ttkclark
9 years ago

This introduces a change which now throws notices when $handle is an array. Of course, the wp_enqueue_script and wp_enqueue_style functions are not documented to accept arrays, they may be (and have been) used as such -- even by at least one of the most popular plugins on

Up until earlier this month in the trunk commit for 4.2 [31028], the unintended consequences of calling the following code were that multiple handles could be enqueued at once. Documentation in code and in codex says it's a string, but it threw no notices or errors, or doing it wrong's.

wp_enqueue_script( array( 'jquery', 'etc', 'etc2' ) );

With that, should a new ticket be opened up to add documented support for array as $handle in wp_enqueue_script and wp_enqueue_style, or would this ticket need to have a new patch applied which at minimal removes the notice that's introduced in 4.2 for undocumented use of arrays?

#13 in reply to: ↑ 12 @SergeyBiryukov
9 years ago

Replying to sc0ttkclark:

This introduces a change which now throws notices when $handle is an array.

Related: #31636

This ticket was mentioned in Slack in #core by drew. View the logs.

9 years ago

#15 @ocean90
9 years ago

In 31887:

Avoid a PHP notice in wp_enqueue_script() if $handle is an array.

Calling wp_enqueue_script() with an array as the first argument is a "hidden feature" and should be avoided. Use dependencies instead.

props sorich87 for initial patch.
fixes #31636.
see #14488.

Note: See TracTickets for help on using tickets.