Remove ‘type’ attribute in Drupal 7 – Say goodbye style, script & link!

Remove 'type' attribute in Drupal 7 - Say goodbye style, script & link!

Here’s a quick tip to remove the type attribute in Drupal 7 to make your site more HTML5 code compliant. This along with other HTML5 features allows for less code on the front-end… and who doesn’t like less code?!

No longer do you need to include this attribute in your script, style and link tags. As an added bonus, this Drupal hook will also remove CDATA comments. They only existed to satisfy the XHTML validator and it too has gone away with the release of HTML5.

Remove type attribute Drupal 7: function theme_process_html_tag

See! for more details.

function bmarshall_process_html_tag(&$vars) {
  $el = &$vars['element'];

  // Remove type="..." and CDATA prefix/suffix.
  unset($el['#attributes']['type'], $el['#value_prefix'], $el['#value_suffix']);

  // Remove media="all" but leave others unaffected.
  if (isset($el['#attributes']['media']) && $el['#attributes']['media'] === 'all') {

Check out the comparison below of the before and after using a slimmed down result.

XHTML Before: with the type attribute

<link rel="stylesheet" href="..." type="text/css" media="all">

<style type="text/css" media="all">
/* CSS code here. */

<script type="text/javascript">
/* JavaScript code here. */

HTML5 After: without the type attribute

<link rel="stylesheet" href="...">

/* CSS code here. */

/* JavaScript Code here. */

Author: Ben Marshall

Red Bull Addict, Self-Proclaimed Grill Master, Entrepreneur, Workaholic, Front End Engineer, SEO/SM Strategist, Web Developer, Blogger

One thought on “Remove ‘type’ attribute in Drupal 7 – Say goodbye style, script & link!”

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.