WordPress at a glance

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.

Works based on: wp_get_custom_css_post()
Basis of: wp_custom_css_cb()
1 time = 0.005268s = very slow | 50000 times = 9.44s = 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

#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.

Code of wp_get_custom_css() WP 5.5.1

<?php
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>.
	 *
	 * @since 4.7.0
	 *
	 * @param string $css        CSS pulled in from the Custom CSS CPT.
	 * @param string $stylesheet The theme stylesheet name.
	 */
	$css = apply_filters( 'wp_get_custom_css', $css, $stylesheet );

	return $css;
}

From tag: styles (include files)

More from category: Scripts and Styles

No comments
    Log In . Register