Make WordPress Core

Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#54314 closed enhancement (duplicate)

Can not add script attribute with wp_enqueue_script()

Reported by: emrancu's profile 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.


3 years ago
#1

  • 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
3 years ago

Need to add following attributes:

  1. type
  2. async
  3. crossorigin
  4. defer
  5. integrity
  6. nonce
  7. referrerpolicy
Version 0, edited 3 years ago by emrancu (next)

#3 @lkraav
3 years ago

Did you do your research?

#12009 and #22249, maybe others.

#4 @SergeyBiryukov
3 years 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.

emrancu commented on PR #1775:


3 years ago
#5

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.