wp_custom_css_cb()WP 4.7.0

Displays <style> tag containing CSS styles added in "Additional CSS" pane of the Theme Customizer.

Before displaying, the code of the styles is sanitized with the strip_tags() function.

To get these CSS styles without displaying them, use wp_get_custom_css().

This function is called by WordPress automatically on wp_head action and output current theme styles.

No Hooks.

Return

null. Nothing (null).

Usage

wp_custom_css_cb();

Examples

0

#1 Additional CSS styles from Theme Customizer (from settings)

The following code is used by default in WordPress to display styles in the HEAD part of the document:

add_action( 'wp_head', 'wp_custom_css_cb', 101 );

I.E. WordPress automatically adds Additional styles for any theme!

Changelog

Since 4.7.0 Introduced.

wp_custom_css_cb() code WP 6.4.3

<?php
function wp_custom_css_cb() {
	$styles = wp_get_custom_css();
	if ( $styles || is_customize_preview() ) :
		$type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"';
		?>
		<style<?php echo $type_attr; ?> id="wp-custom-css">
			<?php
			// Note that esc_html() cannot be used because `div &gt; span` is not interpreted properly.
			echo strip_tags( $styles );
			?>
		</style>
		<?php
	endif;
}