Last active
December 23, 2015 00:39
-
-
Save stephenscaff/6554721 to your computer and use it in GitHub Desktop.
Wordpress can get pretty grimey in the head, droppin in all kinds of nasty bits. So, I always include a cleanup.php deal (included within functions.php), with a bunch of functions to tidy up the nav, body class, lang, js and css outputs, et cetera, et cetera. Here's the Mr. Clean treatment for js and css output. Of course, remember to prefix boss.
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
<?php | |
/*-----------------------------------------------------------------------------------*/ | |
/* Clean them stylesheet <link> tags | |
/*-----------------------------------------------------------------------------------*/ | |
function clean_style_tag($input) { | |
preg_match_all("!<link rel='stylesheet'\s?(id='[^']+')?\s+href='(.*)' type='text/css' media='(.*)' />!", $input, $matches); | |
// Display media if it's print | |
$media = $matches[3][0] === 'print' ? ' media="print"' : ''; | |
return '<link rel="stylesheet" href="' . $matches[2][0] . '"' . $media . '>' . "\n"; | |
} | |
add_filter('style_loader_tag', 'clean_style_tag'); | |
/*-----------------------------------------------------------------------------------*/ | |
/* Remove versions from css/js while we're at it | |
/*-----------------------------------------------------------------------------------*/ | |
function remove_cssjs_ver( $src ) { | |
if( strpos( $src, '?ver=' ) ) | |
$src = remove_query_arg( 'ver', $src ); | |
return $src; | |
} | |
add_filter( 'style_loader_src', 'remove_cssjs_ver', 1000 ); | |
add_filter( 'script_loader_src', 'remove_cssjs_ver', 1000 ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment