Skip to content

Instantly share code, notes, and snippets.

@ingozoell
Created May 8, 2014 20:24
Show Gist options
  • Save ingozoell/2598a81fc038f3b7bf23 to your computer and use it in GitHub Desktop.
Save ingozoell/2598a81fc038f3b7bf23 to your computer and use it in GitHub Desktop.
Clean up output of stylesheet
/*
------------------------------------------------------------------------------------------
Clean up output of stylesheet <link> tags
------------------------------------------------------------------------------------------ */
function my_clean_style_tag($input) {
preg_match_all("!<link rel='stylesheet'\s?(id='[^']+')?\s+href='(.*)' type='text/css' media='(.*)' />!", $input, $matches);
// Only display media if it is meaningful
$media = $matches[3][0] !== '' && $matches[3][0] !== 'all' ? ' media="' . $matches[3][0] . '"' : '';
return '<link rel="stylesheet" href="' . $matches[2][0] . '"' . $media . '>' . "\n";
}
add_filter('style_loader_tag', 'my_clean_style_tag');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment