WP_Styles::print_inline_style
Prints extra CSS styles of a registered stylesheet.
Method of the class: WP_Styles{}
No Hooks.
Returns
String|true|false. False if no data exists, inline styles if $display is true, true otherwise.
Usage
global $wp_styles; $wp_styles->print_inline_style( $handle, $display );
- $handle(string) (required)
- The style's registered handle.
- $display(true|false)
- Whether to print the inline style instead of just returning it.
Default: true
Changelog
| Since 3.3.0 | Introduced. |
WP_Styles::print_inline_style() WP Styles::print inline style code WP 6.9
public function print_inline_style( $handle, $display = true ) {
$output = $this->get_data( $handle, 'after' );
if ( empty( $output ) || ! is_array( $output ) ) {
return false;
}
if ( ! $this->do_concat ) {
// Obtain the original `src` for a stylesheet possibly inlined by wp_maybe_inline_styles().
$inlined_src = $this->get_data( $handle, 'inlined_src' );
// If there's only one `after` inline style, and that inline style had been inlined, then use the $inlined_src
// as the sourceURL. Otherwise, if there is more than one inline `after` style associated with the handle,
// then resort to using the handle to construct the sourceURL since there isn't a single source.
if ( count( $output ) === 1 && is_string( $inlined_src ) && strlen( $inlined_src ) > 0 ) {
$source_url = esc_url_raw( $inlined_src );
} else {
$source_url = rawurlencode( "{$handle}-inline-css" );
}
$output[] = sprintf(
'/*# sourceURL=%s */',
$source_url
);
}
$output = implode( "\n", $output );
if ( ! $display ) {
return $output;
}
printf(
"<style id='%s-inline-css'%s>\n%s\n</style>\n",
esc_attr( $handle ),
$this->type_attr,
$output
);
return true;
}