WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 5 years ago

#11944 closed defect (bug) (duplicate)

Allow wp_enqueue_script() after wp_head()

Reported by: scribu Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: General Keywords: needs-patch
Focuses: Cc:

Description

Say you have this code:

function my_template_tag() {
  // output some stuff here

  wp_enqueue_script('handle', ..., $in_footer = true);
}

It should just work, even if it's called after wp_head().

Currently, you have to do something like this:

function my_template_tag() {
  // output some stuff here

  add_action('wp_footer', 'my_template_tag_script');
}

function my_template_tag_script() {
  wp_register_script('handle', ...);
  wp_print_scripts('handle');
}

Change History (4)

comment:1 @archon8105 years ago

+1 for this.

Some discussion here, here, and here.

comment:2 @TobiasBg5 years ago

  • Cc wordpress@… added

huge +1

comment:4 @scribu5 years ago

  • Milestone Future Release deleted
  • Resolution set to duplicate
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.