Last active
February 7, 2019 11:35
-
-
Save sergeliatko/6c4a7d1c9f20776322612f3d47a29bef to your computer and use it in GitHub Desktop.
Returns current stylesheet registration handle.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Returns current stylesheet handle used in wp_register_style() function or NULL if not found. | |
* | |
* @return string|null | |
*/ | |
function get_current_stylesheet_handle() { | |
$pattern = sprintf( | |
'/%1$s\/style\.(min\.)?css/', | |
str_replace( '/', '\/', untrailingslashit( get_stylesheet_directory_uri() ) ) | |
); | |
/** @var \_WP_Dependency $style */ | |
foreach ( (array) wp_styles()->registered as $style ) { | |
if ( preg_match( $pattern, $style->src ) ) { | |
return $style->handle; | |
} | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment