Created
May 8, 2014 20:24
-
-
Save ingozoell/2598a81fc038f3b7bf23 to your computer and use it in GitHub Desktop.
Clean up output of stylesheet
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
/* | |
------------------------------------------------------------------------------------------ | |
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