Created
August 14, 2018 11:22
-
-
Save ambercouch/6f9a0528ce8027ab56b712d7eb05bd79 to your computer and use it in GitHub Desktop.
Remove all the style sheets from a wordpress theme except $styles_to_keep
This file contains 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
// add the action | |
add_action('wp_print_styles', 'ac_remove_default_styles'); | |
function ac_remove_default_styles () | |
{ | |
// get all styles data | |
global $wp_styles; | |
$styles_to_keep = array('admin-menu'); | |
// loop over all of the registered scripts | |
foreach ($wp_styles->registered as $handle => $data) | |
{ | |
// if we want to keep it, skip it | |
if ( in_array($handle, $styles_to_keep) ){ | |
//do nothing | |
}else{ | |
// otherwise remove it | |
wp_deregister_style($handle); | |
wp_dequeue_style($handle); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment