WordPress.org

Make WordPress Core

Opened 6 months ago

Last modified 6 months ago

#40276 new enhancement

enhancement: add a $type parameter to wp_add_inline_script()

Reported by: paulschreiber Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.7.3
Component: General Keywords:
Focuses: Cc:

Description

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 (2)

#1 @paulschreiber
6 months 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
6 months ago

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

Note: See TracTickets for help on using tickets.