Autoptimize honors the original CSS’s media-type, so you end up with media="all" for one and media="screen" @graphettion
hope this clarifies,
frank
Awesome! Thank you for the speedy response. So you’re saying they should all be either media=”all” or media=”screen”, not both. Correct? If so, which do you think would be better or does it matter?
Ex:
<link href=”path/to/css/file/style-1.css” rel=”stylesheet” type=”text/css” media=”all”>
<link href=”path/to/css/file/style-2.css” rel=”stylesheet” type=”text/css” media=”all”>
Or
Ex:
<link href=”path/to/css/file/style-1.css” rel=”stylesheet” type=”text/css” media=”screen”>
<link href=”path/to/css/file/style-2.css” rel=”stylesheet” type=”text/css” media=”screen”>
I replaced all instances of media=”screen” with media=”all” and it still shows two .css files. Am I missing something?
// Replace media="screen" with media="all"
function replace_style_media_type($htmlIn) {
$htmlOut = str_replace('media="screen"', 'media="all"', $htmlIn);
return $htmlOut;
}
add_filter('autoptimize_html_after_minify','replace_style_media_type');
autoptimize_html_after_minify is too late already, give autoptimize_filter_html_before_minify a try 🙂
I ran that code and it didn’t work. It went back to media=”screen” and still shows two css files.
This code works for adding both CSS files as media=”all”:
function replace_style_media_type($htmlIn) {
$htmlOut = str_replace('media="screen"', 'media="all"', $htmlIn);
return $htmlOut;
}
add_filter('autoptimize_html_after_minify','replace_style_media_type');
But still shows two css files. :/
autoptimize_html_after_minify will never work as at that point AO’s work is done @graphettion. autoptimize_filter_html_before_minify _should_ work, could be double vs single quotes. alternative is autoptimize_filter_css_tagmedia, cfr. https://blog.futtta.be/2016/10/04/how-to-fix-css-media-types-impacting-autoptimized-css-order/
frank
Errr. It was the single quote thing. Bleh!
I also just want to thank you Frank and everyone who has helped with the AO plugin. You guys are not only great with making websites on wordpress painlessly easy and faster, but you also open source it. Love it.
Thanks again Frank! 😀
happy it works @graphettion, enjoy your weekend! 🙂
frank