wp_style_is()
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, $status );
- $handle(string) (required)
- Name of the stylesheet.
- $status(string)
- Status of the stylesheet to check. Accepts 'enqueued', 'registered', 'queue', 'to_do', and 'done'.
Default: 'enqueued'
Examples
#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. |
wp_style_is() wp style is code WP 6.7.1
function wp_style_is( $handle, $status = 'enqueued' ) { _wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle ); return (bool) wp_styles()->query( $handle, $status ); }