wp_style_is()WP 2.8.0

Check whether a CSS stylesheet has been added to the queue.

No Hooks.

Return

true|false. Whether style is queued.

Usage

wp_style_is( $handle, $list );
$handle(string) (required)
Name of the stylesheet.
$list(string)
Status of the stylesheet to check. Accepts 'enqueued', 'registered', 'queue', 'to_do', and 'done'.
Default: 'enqueued'

Examples

0

#1 Demo

Suppose we added a styles file to the output queue, registering it beforehand:

// connect the styles
add_action( 'wp_enqueue_scripts', 'theme_name_scripts' );

function theme_name_scripts() {
	wp_enqueue_style( 'style-name', get_stylesheet_uri() );
}

Now, let's do the same thing, only with a preliminary check whether the file is already added to the queue, if it is added do nothing:

add_action( 'wp_enqueue_scripts', 'theme_name_scripts' );

function theme_name_scripts() {

	// styles are not connected, let's connect them
	if( ! wp_style_is( 'style-name' ) ){
		wp_enqueue_style( 'style-name', get_stylesheet_uri() );
	}
}

Changelog

Since 2.8.0 Introduced.

Code of wp_style_is() WP 6.0

function wp_style_is( $handle, $list = 'enqueued' ) {
	_wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle );

	return (bool) wp_styles()->query( $handle, $list );
}