wp_custom_css_cb()
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.
Uses: wp_get_custom_css()
No Hooks.
Returns
null. Nothing (null).
Usage
wp_custom_css_cb();
Examples
#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() wp custom css cb code WP 7.0
function wp_custom_css_cb() {
$styles = wp_get_custom_css();
if ( ! $styles && ! is_customize_preview() ) {
return;
}
$processor = new WP_HTML_Tag_Processor( '<style></style>' );
$processor->next_tag();
$processor->set_attribute( 'id', 'wp-custom-css' );
$processor->set_modifiable_text( "\n{$styles}\n" );
echo "{$processor->get_updated_html()}\n";
}