wp_add_inline_style

Add extra CSS styles to a registered stylesheet.

Description

wp_add_inline_style( (string) $handle, (string) $data ); 

Styles will only be added if the stylesheet in already in the queue. Accepts a string $data containing the CSS. If two or more CSS code blocks are added to the same stylesheet $handle, they will be printed in the order they were added, i.e. the latter added styles can redeclare the previous.

Parameters (2)

0. $handle (string)
Name of the stylesheet to add the extra styles to.
1. $data (string)
String containing the CSS styles to be added.

Usage

  1. if ( !function_exists( 'wp_add_inline_style' ) ) { 
  2. require_once ABSPATH . WPINC . '/functions.wp-styles.php'; 
  3.  
  4. // Name of the stylesheet to add the extra styles to. 
  5. $handle = ''; 
  6.  
  7. // String containing the CSS styles to be added. 
  8. $data = ''; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = wp_add_inline_style($handle, $data); 
  12.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/functions.wp-styles.php  
  1. function wp_add_inline_style( $handle, $data ) { 
  2.  
  3. if ( false !== stripos( $data, '</style>' ) ) { 
  4. _doing_it_wrong( __FUNCTION__, sprintf( 
  5. /** translators: 1: <style>, 2: wp_add_inline_style() */ 
  6. __( 'Do not pass %1$s tags to %2$s.' ),  
  7. '<code><style></code>',  
  8. '<code>wp_add_inline_style()</code>' 
  9. ), '3.7.0' ); 
  10. $data = trim( preg_replace( '#<style[^>]*>(.*)</style>#is', '$1', $data ) ); 
  11.  
  12. returnwp_styles)->add_inline_style( $handle, $data );