WordPress.org

Make WordPress Core

Opened 5 weeks ago

Closed 5 weeks ago

Last modified 4 weeks ago

#54314 closed enhancement (duplicate)

Can not add script attribute with wp_enqueue_script()

Reported by: emrancu Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Script Loader Keywords: has-patch
Focuses: javascript Cc:

Description

There is no option to add custom attributes to the script tag.
I need to add a type attribute to the script tag but no way.

Change History (5)

This ticket was mentioned in PR #1775 on WordPress/wordpress-develop by emrancu.


5 weeks ago

  • Keywords has-patch added

There is not option for setting script attributes ( like 'async', 'crossorigin', 'defer', 'integrity', 'nonce', 'referrerpolicy', 'type' ).
I have added support to add custom attribute/s to script tag with the wp_enqueue_script method.

Trac ticket: https://core.trac.wordpress.org/ticket/54314

#2 @emrancu
5 weeks ago

May need to add following attributes:

  1. type
  2. async
  3. crossorigin
  4. defer
  5. integrity
  6. nonce
  7. referrerpolicy
Last edited 5 weeks ago by emrancu (previous) (diff)

#3 @lkraav
5 weeks ago

Did you do your research?

#12009 and #22249, maybe others.

#4 @SergeyBiryukov
5 weeks ago

  • Component changed from General to Script Loader
  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from assigned to closed

Hi there, welcome to WordPress Trac! Thanks for the ticket and the patch.

As noted above, we're already tracking this enhancement in #22249, let's continue the discussion there.

#5 @prbot
4 weeks ago

emrancu commented on PR #1775:

WordPress 5.7 has wp_print_script_tag function but it is for front-end only but I need a custom attribute for admin-end.
I will solve the issue on my end with this type of custom function.

Thanks

Note: See TracTickets for help on using tickets.