On this page
wp_add_inline_style( string $handle, string $data ): bool
Add extra CSS styles to a registered stylesheet.
Description
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.
See also
Parameters
$handlestring Required-
Name of the stylesheet to add the extra styles to.
$datastring Required-
String containing the CSS styles to be added.
Return
bool True on success, false on failure.
Source
File: wp-includes/functions.wp-styles.php. View all references
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
Uses
| Uses | Description |
|---|---|
| stripos() wp-includes/class-pop3.php | |
| wp_styles() wp-includes/functions.wp-styles.php | Initialize $wp_styles if it has not been set. |
| WP_Styles::add_inline_style() wp-includes/class-wp-styles.php | Adds extra CSS styles to a registered stylesheet. |
| __() wp-includes/l10n.php | Retrieves the translation of $text. |
| _doing_it_wrong() wp-includes/functions.php | Marks something as being incorrectly called. |
Used By
| Used By | Description |
|---|---|
| wp_enqueue_stored_styles() wp-includes/script-loader.php | Fetches, processes and compiles stored core styles, then combines and renders them to the page. |
| wp_add_global_styles_for_blocks() wp-includes/global-styles-and-settings.php | Adds global style rules to the inline style for each block. |
| _wp_theme_json_webfonts_handler() wp-includes/script-loader.php | Runs the theme.json webfonts handler. |
| wp_enqueue_global_styles_css_custom_properties() wp-includes/script-loader.php | Function that enqueues the CSS Custom Properties coming from theme.json. |
| wp_enqueue_global_styles() wp-includes/script-loader.php | Enqueues the global styles defined via theme.json. |
| enqueue_block_styles_assets() wp-includes/script-loader.php | Function responsible for enqueuing the styles required for block styles functionality on the editor and on the frontend. |
| wp_common_block_scripts_and_styles() wp-includes/script-loader.php | Handles the enqueueing of block scripts and styles that are common to both the editor and the front-end. |
Changelog
| Version | Description |
|---|---|
| 3.3.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/wp_add_inline_style