Skip to content

Instantly share code, notes, and snippets.

@geekontheroad
Last active May 14, 2023 06:32
Show Gist options
  • Save geekontheroad/bb5b1396cc33ce72bbf606b7cf579f5b to your computer and use it in GitHub Desktop.
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.
<?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