wp_get_custom_css()WP 4.7.0

Fetches the CSS code from the Theme Customizer settings. The CSS will be retrieved as it is: without a <style> pane.

These styles are saved in the Theme Customizer in "Additional CSS" pane.

To display the Custom CSS wrapped in the <style> tag, use wp_get_custom_css() function.

These styles are displayed automatically by the WordPress itself in the HEAD of the theme during the wp_head action.

1 time — 0.005268 sec (very slow) | 50000 times — 9.44 sec (fast) | PHP 7.1.5, WP 4.9.1
Hooks from the function

Return

String. The Custom CSS Post content.

Usage

wp_get_custom_css( $stylesheet );
$stylesheet(string)
Theme directory name. See get_stylesheet().
Default: current theme

Examples

0

#1 Get the Custom CSS for the theme

Suppose that we have added some custom CSS in the Theme Customizer in "Additional CSS" pane and now we want to display theme somewhere:

echo '<style>'. wp_get_custom_css() .'</style>';

Changelog

Since 4.7.0 Introduced.

wp_get_custom_css() code WP 6.5.2

function wp_get_custom_css( $stylesheet = '' ) {
	$css = '';

	if ( empty( $stylesheet ) ) {
		$stylesheet = get_stylesheet();
	}

	$post = wp_get_custom_css_post( $stylesheet );
	if ( $post ) {
		$css = $post->post_content;
	}

	/**
	 * Filters the custom CSS output into the head element.
	 *
	 * @since 4.7.0
	 *
	 * @param string $css        CSS pulled in from the Custom CSS post type.
	 * @param string $stylesheet The theme stylesheet name.
	 */
	$css = apply_filters( 'wp_get_custom_css', $css, $stylesheet );

	return $css;
}