WordPress.org

Make WordPress Core

Opened 7 months ago

Last modified 5 months ago

#42804 new enhancement

type is not required in HTML5

Reported by: sasiddiqui Owned by:
Milestone: 5.0 Priority: low
Severity: normal Version:
Component: Script Loader Keywords: needs-testing has-patch
Focuses: Cc:

Description

type is no more required in style and script tags in HTML5. Now HTML Validator start throwing warnings on the script and style tags which contains the types.

Attaching a path which fixes the issues for inline and enqueued files (CSS and JS).

Attachments (6)

class.wp-scripts.php (13.7 KB) - added by sasiddiqui 7 months ago.
Fixed the type issue with enqueue and inline script tags
class.wp-styles.php (9.5 KB) - added by sasiddiqui 7 months ago.
Fixed the type issue with enqueue and inline style tags
class.wp-styles.2.php (9.5 KB) - added by sasiddiqui 7 months ago.
Fixed the type issue with enqueue and inline style tags updated
wp-includes.patch (13.6 KB) - added by sasiddiqui 7 months ago.
42804.patch (6.2 KB) - added by sasiddiqui 7 months ago.
42804-update1.patch (6.2 KB) - added by sasiddiqui 7 months ago.

Download all attachments as: .zip

Change History (21)

@sasiddiqui
7 months ago

Fixed the type issue with enqueue and inline script tags

@sasiddiqui
7 months ago

Fixed the type issue with enqueue and inline style tags

#1 @knutsp
7 months ago

  • Type changed from defect (bug) to enhancement

Hello and welcome to track, sasiddiqui.

Thank your for your suggestion. I agree this would be a nice enhancement. When validating html these warnings comes up. WordPress could do better with making correct html.

Are you able to make a patch with just the changes you propose?

#2 @swissspidy
7 months ago

  • Component changed from General to Script Loader
  • Priority changed from normal to low
  • Version trunk deleted

Please have a look at https://make.wordpress.org/core/handbook/tutorials/working-with-patches/ in order to create patch files that can be more easily scanned. Uploading whole files is unfortunately not really helpful.

Also, just because type is not required anymore with HTML5, it doesn't mean every website or teme is using HTML5. In HTML4 and other doc types, the type attribute is required and will cause validation errors (not just warnings as in your example).

Just removing type might not the best solution. Maybe we need to use add_theme_support for this?

@sasiddiqui
7 months ago

Fixed the type issue with enqueue and inline style tags updated

#3 @sasiddiqui
7 months ago

@knutsp Thanks. @swissspidy Sorry about the improper attachments. Would create a patch and add it again.

Apology for the improper files.

#4 @sasiddiqui
7 months ago

  • Keywords has-patch needs-testing added

@knutsp @swissspidy Patch has been attached. Let me know if i have done any mistake in it.

@swissspidy As per your concern about the HTML 4 so, i am not sure but i think, mostly themes are working on HTML 5 specially the sites which are working on the latest WordPress Version. It's quite long time when HTML 5 had been introduced.

But, if you guys think that we still need to support the HTML 4 so, we can also add the filter for HTML 4 which doesn't remove the type attr from the script and style tags.

#5 @swissspidy
7 months ago

  • Keywords needs-patch added; has-patch removed

Patch has been attached. Let me know if i have done any mistake in it.

Much better, but the patch should only change the lines in question. Right now, it changes lots of the coding style throughout the files and the patch is very long and difficult to scan because of this. It's recommended not to touch irrelevant code sections.

For now and updated code you can use PHP Code Sniffer with the WP Coding Standards (https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards) to automatically correct coding standards mistakes. The WordPress Git repository contains a phpcs.xml.dist file to automatically configure PHPCS for that.

But, if you guys think that we still need to support the HTML 4 so, we can also add the filter for HTML 4 which doesn't remove the type attr from the script and style tags.

That's what I meant with add_theme_support. There's precedence for that. See https://developer.wordpress.org/reference/functions/add_theme_support/#html5

#6 follow-up: @knutsp
7 months ago

Something like add_theme_support( 'html5', [ 'script', 'css' ] );?

We already have add_theme_support( 'html5', [ 'comment-list', 'comment-form', 'search-form', 'gallery', 'caption' ] );

Could this be simplified to just add_theme_support( 'html5' ); to catch all?

Last edited 7 months ago by knutsp (previous) (diff)

#7 in reply to: ↑ 6 ; follow-up: @swissspidy
7 months ago

Something like add_theme_support( 'html5', [ 'script', 'css' ] );?

Yeah, something like that.

Could this be simplified to just add_theme_support( 'html5' ); to catch all?

That's how the command worked in the beginning, however it was changed to take an array of features that are supported.

For BC reasons add_theme_support( 'html5' ); is like calling add_theme_support( 'html5', array( 'comment-list', 'comment-form', 'search-form' ) );. I don't think we can change that. Plus, this would warrant its own ticket.

#8 in reply to: ↑ 7 @knutsp
7 months ago

Replying to swissspidy:

For BC reasons add_theme_support( 'html5' ); is like calling add_theme_support( 'html5', array( 'comment-list', 'comment-form', 'search-form' ) );. I don't think we can change that.

Why not?

Own ticket, of course.

@sasiddiqui
7 months ago

#9 @sasiddiqui
7 months ago

  • Keywords has-patch added; needs-patch removed

Please check this patch: https://core.trac.wordpress.org/attachment/ticket/42804/42804-update1.patch

You need to add the add_theme_support in functions.php to remove make the code work.

Something like:

add_theme_support( 'html5', array( 'comment-list', 'comment-form', 'search-form', 'script', 'style' ) );

or

add_theme_support( 'html5', array( 'script', 'style' ) );

#10 @swissspidy
6 months ago

#42977 was marked as a duplicate.

#11 @ocean90
5 months ago

#43079 was marked as a duplicate.

#12 @reeslo
5 months ago

This patch was not added to 4.9.2 ?

#13 @swissspidy
5 months ago

  • Milestone changed from Awaiting Review to 5.0

@reeslo No, this was not added in 4.9.2 as you can see from the history above. The ticket wasn't added to the 4.9.x milestone at any point. However, I think we can add this to 5.0.

#14 @swissspidy
5 months ago

#43111 was marked as a duplicate.

#15 @sasiddiqui
5 months ago

@swissspidy Can i own this ticket?

Note: See TracTickets for help on using tickets.