Opened 9 years ago
Closed 9 years ago
#35643 closed defect (bug) (fixed)
wp_enqueue_script() with an alias handle doesn't work in footer
Reported by: | kovshenin | Owned by: | |
---|---|---|---|
Milestone: | 4.5 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Script Loader | Keywords: | has-patch has-unit-tests |
Focuses: | Cc: |
Description
When registering an alias script (similar to how jquery is an alias for jquery-core and jquery-migrate) in the footer, none of the declared dependencies are processed.
This works:
add_action( 'wp_enqueue_scripts', function() { wp_register_script( 'foo', false, array( 'bar', 'baz' ), '1.0' ); wp_register_script( 'bar', home_url( 'bar.js' ), array(), '1.0' ); wp_register_script( 'baz', home_url( 'baz.js' ), array(), '1.0' ); wp_enqueue_script( 'foo' ); });
This doesn't (no output):
add_action( 'wp_enqueue_scripts', function() { wp_register_script( 'foo', false, array( 'bar', 'baz' ), '1.0', true ); wp_register_script( 'bar', home_url( 'bar.js' ), array(), '1.0', true ); wp_register_script( 'baz', home_url( 'baz.js' ), array(), '1.0', true ); wp_enqueue_script( 'foo' ); });
Attachments (1)
Change History (8)
#3
@
9 years ago
Have you tried the patch with jQuery? I tried the patch with the following snippet and it did not work.
<?php function grappler_move_jquery_to_footer( &$scripts ) { if( is_admin() ) { return; } $scripts->add_data( 'jquery', 'group', 1 ); $scripts->add_data( 'jquery-core', 'group', 1 ); $scripts->add_data( 'jquery-migrate', 'group', 1 ); } add_action( 'wp_default_scripts', 'grappler_move_jquery_to_footer', 11 );
When I was trying to make it work I looked at https://github.com/WordPress/WordPress/blob/4.4-branch/wp-includes/class.wp-dependencies.php#L111. It adds the alias script to the header without checking the group.
#4
@
9 years ago
@grapplerulrich Yeah it works with jQuery. The code you referenced is the code that's moved out of the dependencies class and into the scripts and styles subclasses instead. Are you sure you applied the patch? And also, make sure no other header scripts declare a jquery dependency, otherwise WordPress will still obey the dependency and print jQuery in the header, regardless of its footer group.
In 35643.diff: Move the src empty check to
do_item()
after groups have been checked.