Make WordPress Core

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#43111 closed defect (bug) (duplicate)

W3C validation warnings: type attribute

Reported by: artgoddess's profile ArtGoddess Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.9.2
Component: Script Loader Keywords:
Focuses: Cc:

Description

Hello,

After deactivating all plugins and switching to Twenty Seventeen theme, I can see a huge quantity of warnings.

The type attribute is unnecessary for JavaScript resources.

and

The type attribute for the style element is not needed and should be omitted.

After a Google search, I have found some pages that provide useful functions for get rid of the type attribute.

https://www.lee-harris.co.uk/blog/remove-type-attribute-script-tags-wordpress/

https://wordpress.stackexchange.com/questions/287830/remove-type-attribute-from-script-and-style-tags-added-by-wordpress

https://stackoverflow.com/questions/47906924/remove-type-attribute-from-script-and-style-tags-in-wordpress

The fact is that none of the presented functions remove all the type=”text/javascript” and type=”text/css”, for some factors. For example, how scripts and styles are enqueued, or if they use single or double quotes.

wp-includes\class.wp-scripts.php

$tag = "{$cond_before}{$before_handle}<script type='text/javascript' src='$src'></script>\n{$after_handle}{$cond_after}";

Also wp-includes\class.wp-styles.php adds the type=’text/css’ attribute.

Even if I delete the type='text/javascript' from line 327 I can see that default WP Emojis javascript and css style, use type=”text/css” and type=”text/javascript”.

I have two questions:

  1. Has WordPress any plan to get rid of these warnings in order to follow W3C guidelines?
  1. Can someone please provide a function in order to remove all these warnings? Please, if you don’t care about W3C warnings, do not reply to this post.

Thank you.

https://wordpress.org/support/topic/w3c-validation-warnings-type-attribute/

Change History (2)

#1 @swissspidy
7 years ago

  • Component changed from General to Script Loader
  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Hey there

Thanks for your report and welcome to WordPress Trac! This issue has been reported multiple times and we're already tracking it in #42804. Please look for existing tickets before opening a new one :-)

With that being said, there are different types of HTML standards and type is required in some of them. Omitting them will lead to validation errors. In your case there are only warnings because the type attribute is not required anymore with HTML 5, but it also doesn't cause any problems when it's there. So it's not that big of a big deal really.

The latest patch on #42804 resolves this issue by allowing themes to omit the type attribute. The ticket is currently slated for the WordPress 5.0 release.

#2 @ArtGoddess
7 years ago

Thank you @swissspidy for your answer. Sorry if this has been reported before, this was my very first ticket :) Will follow https://core.trac.wordpress.org/ticket/42804

Note: See TracTickets for help on using tickets.