Skip to content

Instantly share code, notes, and snippets.

@ambercouch
Created August 14, 2018 11:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ambercouch/6f9a0528ce8027ab56b712d7eb05bd79 to your computer and use it in GitHub Desktop.
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
// 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