Last active
May 14, 2023 06:32
-
-
Save geekontheroad/bb5b1396cc33ce72bbf606b7cf579f5b to your computer and use it in GitHub Desktop.
Adds a new shortcode that will output a list of all CSS that is loaded for that page with their handle and file location.
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 | |
/** | |
* This will output all styles with their handle and file location | |
* | |
* Shortcode: [gotr_enqueued_css] | |
* | |
* @author https://geekontheroad.com | |
***/ | |
function gotr_enqueued_css_shortcode() { | |
ob_start(); // Start output buffering | |
global $wp_styles; | |
// Get the registered styles | |
$registered_styles = $wp_styles->registered; | |
// Loop through the registered styles | |
foreach ($registered_styles as $handle => $style) { | |
// Check if the style is enqueued | |
if ($wp_styles->query($handle)) { | |
echo "Handle: " . $handle . "<br>"; | |
echo "Source: " . $style->src . "<br><br>"; | |
} | |
} | |
return ob_get_clean(); // Return the buffered output | |
} | |
add_shortcode('gotr_enqueued_css', 'gotr_enqueued_css_shortcode'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment