Skip to content
This repository has been archived by the owner on Jan 16, 2024. It is now read-only.

Fixes #100 cleanup bug. Closes #101 #114

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions modules/clean-up.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,11 @@ function language_attributes() {
function 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";
$media = isset($matches[3][0]) && $matches[3][0] !== 'all' ? ' media="' . $matches[3][0] . '"' : '';
// Only display escaped stylesheet url's
$href = isset($matches[2][0]) ? esc_url($matches[2][0]) : '';
// Only display <link> if href exists
return empty($href) ? '' : '<link rel="stylesheet" href="' . $href . '"' . $media . '>' . "\n";
}
add_filter('style_loader_tag', __NAMESPACE__ . '\\clean_style_tag');

Expand Down