When enqueing a stylesheet, is it possible to remove the type attribute? [duplicate]

I’m updating my self-built theme to HTML5, and easily made a number of changes already.

My theme’s sole stylesheet is added to the page head via wp_enqueue_style in the functions.php file, as follows:

function gridded_enqueue_styles() {
    wp_enqueue_style('style', get_template_directory_uri() . '/style.css', array(), null, 'all');
}
add_action('wp_enqueue_scripts', 'gridded_enqueue_styles');

The resulting markup is:

<link rel="stylesheet" id='style-css'  href="http://grantpalin.com.dev:81/wp-content/themes/gridded/style.css" type="text/css" media="all" />

The stylesheet is loaded, the page renders, all good. However, the HTML5 spec indicates that the type attribute is no longer needed for the link, style, and script elements.

Looking through the codex reference, I don’t see a way to alter or remove the type attribute. Can this even be done?

The obvious workaround is to hard-code the stylesheet reference in my header.php, but that’s avoiding the benefit of the enqueue functionality.

2 Answers
2

For modify this output you can use that filter:

function wpse51581_hide_type($src) {
    return str_replace("type="text/css"", '', $src);
}
add_filter('style_loader_tag', 'wpse51581_hide_type');

You can see this hook into wp-includes/class.wp-styles.php

Leave a Comment