Skip to content

Instantly share code, notes, and snippets.

@stephenscaff
Last active December 23, 2015 00:39
Show Gist options
  • Save stephenscaff/6554721 to your computer and use it in GitHub Desktop.
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.
<?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