I want to clean up <script> tags generated by WordPress to produce more semantic output for HTML5.
You can already do this for <style> tags using this code attached to the style_loader_tag filter:
//clean up the default WordPress style tags
add_filter('style_loader_tag', 'clean_style_tag');
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's print
$media = $matches[3][0] === 'print' ? ' media="print"' : '';
return '<link rel="stylesheet" href="' . $matches[2][0] . '"' . $media . '>' . "\n";
}
But there isn't an equivalent script_loader_tag in core yet. It was proposed in the past, but for now we need a workaround.
I've started looking in /wp-includes/class.wp-scripts.php at function do_item( $handle, $group = false ) around line 79 which holds the script output (specifically lines 117-120), but I'm having a bit of trouble finding an appropriate filter that could be used here.
<link rel="stylesheet" id="1234" href="http://site.url/style.css" type="text/css" media="screen" />into<link rel="stylesheet" href="http://site.url/style.css" media="screen" />. So ... remove attributes like "id" and "type". Is this accurate? If so ... why? – EAMann♦ Apr 27 '12 at 15:22scripttags as done for thelinktags - so the output would be<script src="source_url"></script>. To answer your question of "why?" it's to produce more semantic output for HTML5 (we don't need those, so they're useless to keep). That WP bug ticket I linked to expresses the same opinion I have about that (which unfortunately isn't in there yet), so looking for a possible workaround. Thanks. – Zach Apr 27 '12 at 15:46