[wp-trac] [WordPress Trac] #51124: Can we get an additional parameter in wp_add_inline_script to set the script type?

WordPress Trac noreply at wordpress.org
Mon Aug 24 15:55:13 UTC 2020


#51124: Can we get an additional parameter in wp_add_inline_script to set the
script type?
-----------------------------+-----------------------------
 Reporter:  hcabrera         |      Owner:  (none)
     Type:  feature request  |     Status:  new
 Priority:  normal           |  Milestone:  Awaiting Review
Component:  Script Loader    |    Version:
 Severity:  normal           |   Keywords:
  Focuses:                   |
-----------------------------+-----------------------------
 Hi everyone,

 This is probably a feature that not many developers out there will use but
 I think it would be nice to have.

 One of my plugins uses `wp_add_inline_script` to inject an inline script
 into the page. Said inline script gets assigned `text/javascript` as type
 automatically and there doesn't seem to be a way to change that (if there
 is please let me know and I'll gladly close this ticket.)

 My plugin needs said inline script to contain a JSON string and so it
 currently hooks into `script_loader_tag` to change its type to
 `application/json` which feels a bit like a hack. It would be nice if we
 could set the script type via parameter (eg. `wp_add_inline_script( 'some-
 handle', '...', 'before', 'application/json' );`) (or maybe via filter
 hook before `script_loader_tag` happens?)

 Thoughts?

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/51124>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list