Title: wp_style_add_data
Published: April 25, 2014
Last modified: February 24, 2026

---

# wp_style_add_data( string $handle, string $key, mixed $value ): bool

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/wp_style_add_data/?output_format=md#description)
    - [See also](https://developer.wordpress.org/reference/functions/wp_style_add_data/?output_format=md#see-also)
 * [Parameters](https://developer.wordpress.org/reference/functions/wp_style_add_data/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/wp_style_add_data/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/wp_style_add_data/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/wp_style_add_data/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/wp_style_add_data/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/wp_style_add_data/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/functions/wp_style_add_data/?output_format=md#wp--skip-link--target)

Adds metadata to a CSS stylesheet.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/wp_style_add_data/?output_format=md#description)󠁿

Works only if the stylesheet has already been registered.

Possible values for $key and $value: ‘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.

### 󠀁[See also](https://developer.wordpress.org/reference/functions/wp_style_add_data/?output_format=md#see-also)󠁿

 * [WP_Dependencies::add_data()](https://developer.wordpress.org/reference/classes/WP_Dependencies/add_data/)

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/wp_style_add_data/?output_format=md#parameters)󠁿

 `$handle`stringrequired

Name of the stylesheet.

`$key`stringrequired

Name of data point for which we’re storing a value.
 Accepts `'rtl'` and `'suffix'`,`'
alt'`, `'title'` and `'path'`.

`$value`mixedrequired

String containing the CSS data to be added.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/wp_style_add_data/?output_format=md#return)󠁿

 bool True on success, false on failure.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/wp_style_add_data/?output_format=md#source)󠁿

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

[View all references](https://developer.wordpress.org/reference/files/wp-includes/functions-wp-styles.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/functions.wp-styles.php#L244)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/functions.wp-styles.php#L244-L246)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/wp_style_add_data/?output_format=md#related)󠁿

| Uses | Description | 
| [WP_Styles::add_data()](https://developer.wordpress.org/reference/classes/wp_styles/add_data/)`wp-includes/class-wp-styles.php` |

Overrides the add_data method from [WP_Dependencies](https://developer.wordpress.org/reference/classes/wp_dependencies/), to allow unsetting dependencies for conditional styles.

  | 
| [wp_styles()](https://developer.wordpress.org/reference/functions/wp_styles/)`wp-includes/functions.wp-styles.php` |

Initializes $wp_styles if it has not been set.

  |

| Used by | Description | 
| [wp_enqueue_block_style()](https://developer.wordpress.org/reference/functions/wp_enqueue_block_style/)`wp-includes/script-loader.php` |

Enqueues a stylesheet for a specific block.

  | 
| [register_block_style_handle()](https://developer.wordpress.org/reference/functions/register_block_style_handle/)`wp-includes/blocks.php` |

Finds a style handle for the block metadata field. It detects when a path to file was provided and registers the style under automatically generated handle name. It returns unprocessed style handle otherwise.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/wp_style_add_data/?output_format=md#changelog)󠁿

| Version | Description | 
| [6.9.0](https://developer.wordpress.org/reference/since/6.9.0/) | `'conditional'` value changed. If the `'conditional'` parameter is present the stylesheet will be ignored. | 
| [5.8.0](https://developer.wordpress.org/reference/since/5.8.0/) | Added `'path'` as an official value for $key.
 See [wp_maybe_inline_styles()](https://developer.wordpress.org/reference/functions/wp_maybe_inline_styles/). | 
| [3.6.0](https://developer.wordpress.org/reference/since/3.6.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/wp_style_add_data/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 3 content](https://developer.wordpress.org/reference/functions/wp_style_add_data/?output_format=md#comment-content-996)
 2.    [Aamer Shahzad](https://profiles.wordpress.org/talentedaamer/)  [  10 years ago  ](https://developer.wordpress.org/reference/functions/wp_style_add_data/#comment-996)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_style_add_data%2F%23comment-996)
     Vote results for this note: 4[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_style_add_data%2F%23comment-996)
 4.  **Enqueue IE-specific stylesheets with conditional comments**
 5.      ```php
         /**
          * Enqueue styles conditionally using 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' );
         ```
     
 6.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_style_add_data%2F%3Freplytocom%3D996%23feedback-editor-996)
 7.   [Skip to note 4 content](https://developer.wordpress.org/reference/functions/wp_style_add_data/?output_format=md#comment-content-6586)
 8.    [Masoud Golchin](https://profiles.wordpress.org/masoudin/)  [  3 years ago  ](https://developer.wordpress.org/reference/functions/wp_style_add_data/#comment-6586)
 9.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_style_add_data%2F%23comment-6586)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_style_add_data%2F%23comment-6586)
 10. To add an RTL (right-to-left) version of the style when the site is displayed 
     in an RTL language, you can do this:
 11.     ```php
         // Hook into WordPress' enqueue scripts action.
         add_action( 'wp_enqueue_scripts', function () {
         	// Enqueue your stylesheet (style.css).
         	wp_enqueue_style( 'wpdocs-style', get_stylesheet_uri() );
         	// Use wp_style_add_data to indicate an RTL stylesheet is available.
         	wp_style_add_data( 'wpdocs-style', 'rtl', true );
         } );
         ```
     
 12. But if you want to completely swap out the original style with an RTL one when
     the site is viewed in an RTL language:
 13.     ```php
         // Hook into WordPress' enqueue scripts action.
         add_action( 'wp_enqueue_scripts', function () {
         	// Enqueue your stylesheet (style.css).
         	wp_enqueue_style( 'wpdocs-style', get_stylesheet_uri() );
         	// Use wp_style_add_data to replace the original stylesheet with the RTL version.
         	wp_style_add_data( 'wpdocs-style', 'rtl', 'replace' );
         } );
         ```
     
 14. **Important notes:**
 15.  a. Be sure to use **wp_style_add_data** after **wp_enqueue_style**. This guarantees
         that the style you’re trying to modify has been properly registered.
      b. Don’t forget to create **style-rtl.css** in the same location as your **style.
         css**. This ensures that the RTL style will be found and used when needed.
 16.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_style_add_data%2F%3Freplytocom%3D6586%23feedback-editor-6586)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_style_add_data%2F)
before being able to contribute a note or feedback.