WordPress.org

Make WordPress Core

Opened 19 months ago

Last modified 12 days ago

#42804 new enhancement

type is not required in HTML5

Reported by: sasiddiqui Owned by:
Milestone: Future Release 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 19 months ago.
Fixed the type issue with enqueue and inline script tags
class.wp-styles.php (9.5 KB) - added by sasiddiqui 19 months ago.
Fixed the type issue with enqueue and inline style tags
class.wp-styles.2.php (9.5 KB) - added by sasiddiqui 19 months ago.
Fixed the type issue with enqueue and inline style tags updated
wp-includes.patch (13.6 KB) - added by sasiddiqui 19 months ago.
42804.patch (6.2 KB) - added by sasiddiqui 19 months ago.
42804-update1.patch (6.2 KB) - added by sasiddiqui 19 months ago.

Download all attachments as: .zip

Change History (30)

@sasiddiqui
19 months ago

Fixed the type issue with enqueue and inline script tags

@sasiddiqui
19 months ago

Fixed the type issue with enqueue and inline style tags

#1 @knutsp
19 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
19 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
19 months ago

Fixed the type issue with enqueue and inline style tags updated

#3 @sasiddiqui
19 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
19 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
19 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
19 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 19 months ago by knutsp (previous) (diff)

#7 in reply to: ↑ 6 ; follow-up: @swissspidy
19 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
19 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
19 months ago

#9 @sasiddiqui
19 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
18 months ago

#42977 was marked as a duplicate.

#11 @ocean90
18 months ago

#43079 was marked as a duplicate.

#12 @reeslo
17 months ago

This patch was not added to 4.9.2 ?

#13 @swissspidy
17 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
17 months ago

#43111 was marked as a duplicate.

#15 @sasiddiqui
17 months ago

@swissspidy Can i own this ticket?

#16 @ocean90
12 months ago

#44570 was marked as a duplicate.

#17 follow-up: @pento
8 months ago

  • Milestone changed from 5.0 to 5.1

#18 in reply to: ↑ 17 @gabrieldiggs
6 months ago

Replying to pento:
Has this been fixed yet? I'm getting the warnings in W3C validator.

EDIT: Added the following function to my theme functions.php and the W3C validation errors are gone. Is this the right way to fix the issue?

//Remove JS and CSS types

add_action( 'template_redirect', function(){
    ob_start( function( $buffer ){
        $buffer = str_replace( array( 'type="text/javascript"', "type='text/javascript'", 'type="text/css"', "type='text/css'" ), '', $buffer );

        return $buffer;
    });
});
Last edited 6 months ago by gabrieldiggs (previous) (diff)

#19 @pento
6 months ago

  • Milestone changed from 5.1 to Future Release

This patch needs review and a decision.

#20 @sasiddiqui
5 months ago

Is there any update when it can be deployed in WordPress Core? I can understand that it doesn't have such testing yet but it would be great if any time or WordPress version can be mentioned.

#21 @waterworks2
5 months ago

Any chance this will be reviewed and approved soon? Would like to clean up those remaining validation errors and get rid of unnecessary code. Thanks.

#22 @sasiddiqui
5 months ago

@waterworks2 We all are waiting for this.. Hopefully, it will be reviewed and available soon.

#23 @swissspidy
4 months ago

#46447 was marked as a duplicate.

#24 @dackar
12 days ago

Any chance this will be reviewed and approved soon? Would like to clean up those remaining validation errors and get rid of unnecessary code. Thanks.

Note: See TracTickets for help on using tickets.