Make WordPress Core

Opened 7 years ago

Last modified 3 years ago

#40276 new enhancement

enhancement: add a $type parameter to wp_add_inline_script()

Reported by: paulschreiber's profile paulschreiber Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.7.3
Component: Script Loader Keywords:
Focuses: Cc:


It would be helpful to add a $type parameter to wp_add_inline_script().

Currently, it can only output scripts of type text/javascript. If you want something of another type, you need to either use the script_loader_tag filter (which gets run for every script), or manually add the script using a wp_head action.

This will require changing several functions:

  • wp_add_inline_script()
  • WP_Scripts::add_inline_script()
  • WP_Scripts::do_item()
  • WP_Dependencies::add_data()
  • _WP_Dependency::add_data()

Along with the data structure (array) used by add_data.

Change History (4)

#1 @paulschreiber
7 years ago

I originally wrote this up because of MathJax, which wants a block like this:

<script type='text/x-mathjax-config'>

An even more widespread example is the ld+json structured data Google uses everywhere:

<script type='application/ld+json'>

#2 @ronalfy
7 years ago

+1 for this. I currently need to inline some JSON (application/ld+json) and the type parameter must be set.

#3 @SergeyBiryukov
6 years ago

  • Component changed from General to Script Loader
Note: See TracTickets for help on using tickets.