wp_add_inline_style() WP 1.0
Add extra CSS styles to a registered stylesheet.
Styles will only be added if the stylesheet is 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.
Works based on: wp_styles()
No Hooks.
Return
true/false. True on success, false on failure.
Usage
wp_add_inline_style( $handle, $data );
- $handle(string) (required)
- Name of the stylesheet to add the extra styles to.
- $data(string) (required)
- String containing the CSS styles to be added.
Notes
- See: WP_Styles::add_inline_style()
Changelog
Since 3.3.0 | Introduced. |
Code of wp_add_inline_style() wp add inline style WP 5.6
function wp_add_inline_style( $handle, $data ) {
_wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle );
if ( false !== stripos( $data, '</style>' ) ) {
_doing_it_wrong(
__FUNCTION__,
sprintf(
/* translators: 1: <style>, 2: wp_add_inline_style() */
__( 'Do not pass %1$s tags to %2$s.' ),
'<code><style></code>',
'<code>wp_add_inline_style()</code>'
),
'3.7.0'
);
$data = trim( preg_replace( '#<style[^>]*>(.*)</style>#is', '$1', $data ) );
}
return wp_styles()->add_inline_style( $handle, $data );
}Related Functions
From tag: styles (include files)
More from category: Scripts and Styles
- add_editor_style()
- wp_add_inline_script()
- wp_dequeue_script()
- wp_deregister_script()
- wp_enqueue_code_editor()