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

Add metadata to a CSS stylesheet.


Works only if the stylesheet has already been registered.

Possible values for $key and $value: ‘conditional’ string Comments for IE 6, lte IE 7 etc. ‘rtl’ bool|string To declare an RTL stylesheet. ‘suffix’ string Optional suffix, used in combination with RTL. ‘alt’ bool For rel="alternate stylesheet". ‘title’ string For preferred/alternate stylesheets. ‘path’ string The absolute path to a stylesheet. Stylesheet will load inline when ‘path” is set.

Top ↑

See also

Top ↑



(string) (Required) Name of the stylesheet.


(string) (Required) Name of data point for which we're storing a value. Accepts 'conditional', 'rtl' and 'suffix', 'alt', 'title' and 'path'.


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

Top ↑


(bool) True on success, false on failure.

Top ↑


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

function wp_style_add_data( $handle, $key, $value ) {
	return wp_styles()->add_data( $handle, $key, $value );

Top ↑


Version Description
5.8.0 Added 'path' as an official value for $key. See wp_maybe_inline_styles().
3.6.0 Introduced.

Top ↑

User Contributed Notes

  1. Skip to note 1 content
    Contributed by Aamer Shahzad

    Enqueue IE-specific stylesheets with conditional comments

     * Enqueue styles conditionally using {@see wp_style_add_data()}.
     * Example taken from the Twenty Fifteen theme and is used to load
     * stylesheets specifically for IE8 and below. IE10 and above does
     * not support conditional comments in standards mode.
     * @link     https://msdn.microsoft.com/en-us/library/ms537512(v=vs.85).aspx
     * @internal Called from 'wp_enqueue_scripts' action.
    function wpdocs_enqueue_scripts() {
    	// Load the Internet Explorer specific stylesheet.
    	wp_enqueue_style( 'twentyfifteen-ie', get_template_directory_uri() . '/css/ie.css', array( 'twentyfifteen-style' ), '20141010' );
    	wp_style_add_data( 'twentyfifteen-ie', 'conditional', 'lt IE 9' );
    	// Load the Internet Explorer 7 specific stylesheet.
    	wp_enqueue_style( 'twentyfifteen-ie7', get_template_directory_uri() . '/css/ie7.css', array( 'twentyfifteen-style' ), '20141010' );
    	wp_style_add_data( 'twentyfifteen-ie7', 'conditional', 'lt IE 8' );
    add_action( 'wp_enqueue_scripts', 'wpdocs_enqueue_scripts' );

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