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

Add metadata to a CSS stylesheet.


Description Description

Works only if the stylesheet has already been added.

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.

See also See also


Top ↑

Parameters Parameters

$handle

(string) (Required) Name of the stylesheet.

$key

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

$value

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


Top ↑

Return Return

(bool) True on success, false on failure.


Top ↑

Source Source

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

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

Top ↑

Changelog Changelog

Changelog
Version Description
3.6.0 Introduced.


Top ↑

User Contributed Notes 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.