wp_script_add_data( string $handle, string $key, mixed $value )

Add metadata to a script.

Description Description

Works only if the script has already been added.

Possible values for $key and $value: ‘conditional’ string Comments for IE 6, lte IE 7, etc.

See also See also

Top ↑

Parameters Parameters


(string) (Required) Name of the script.


(string) (Required) Name of data point for which we're storing a value.


(mixed) (Required) String containing the data to be added.

Top ↑

Return Return

(bool) True on success, false on failure.

Top ↑

Source Source

File: wp-includes/functions.wp-scripts.php

function wp_script_add_data( $handle, $key, $value ){
	return wp_scripts()->add_data( $handle, $key, $value );

Top ↑

Changelog Changelog

Version Description
4.2.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note content
    Contributed by Abiral Neupane

    Enqueue IE-specific Scripts with conditional comments

    function wpdemo_enqueue_scripts() {
        wp_enqueue_script( 'wpdemo-respond', get_template_directory_uri().'/js/respond.min.js' );
        wp_script_add_data( 'wpdemo-respond', 'conditional', 'lt IE 9' );
        wp_enqueue_script( 'wpdemo-html5shiv',get_template_directory_uri().'/js/html5shiv.js');
        wp_script_add_data( 'wpdemo-html5shiv', 'conditional', 'lt IE 9' );
    add_action( 'wp_enqueue_scripts', 'wpdemo_enqueue_scripts' );

You must log in before being able to contribute a note or feedback.