[Support request] The type attribute is unnecessary for JavaScript resources

Home Forums Support The type attribute is unnecessary for JavaScript resources

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #809060
    Ciomîrtan Andrei

    Hi Tom,

    I use validator for HTML

    https://validator.w3.org/nu/?doc=https%3A%2F%2Fwww.refu.ro%2F

    And the validator give me a warning:

    The type attribute is unnecessary for JavaScript resources.

    Where <script type=”text/javascript”> is the problem for the not fully validate the blog.

    This code in child functions.php help?

    add_action( 'wp_enqueue_scripts', 'generatepress_child_enqueue_scripts' );
    
    add_filter('style_loader_tag', 'myplugin_remove_type_attr', 10, 2);
    add_filter('script_loader_tag', 'myplugin_remove_type_attr', 10, 2);
    
    function myplugin_remove_type_attr($tag, $handle) {
        return preg_replace( "/type=['\"]text\/(javascript|css)['\"]/", '', $tag );
    }

    Thanks!

    GeneratePress 2.2.2
    GP Premium 1.7.7
    #809378
    David
    Staff
    Customer Support

    Hi there,

    these are only warnings, so won’t stop your site from being validated. If you must remove them, then i found this snippet:

    add_action( 'template_redirect', function(){
        ob_start( function( $buffer ){
            $buffer = str_replace( array( 'type="text/javascript"', "type='text/javascript'" ), '', $buffer );        
            return $buffer;
        });
    });
    #1491055
    vast

    WordPress also natively supports HTML5 markup.

    function theme_name_setup() {
        add_theme_support( 'html5', array( 'script', 'style' ) );
    }
    add_action( 'after_setup_theme', 'theme_name_setup' );
    #1491062
    Elvin
    Customer Support

    Hi,

    I believe Tom addressed this already in 3.0.
    https://generatepress.com/forums/topic/the-type-attribute/page/2/#post-1483008

    It is mentioned in the changelog.
    “Tweak: Remove type attribute from scripts and styles”
    https://generatepress.com/generatepress-3-0-a-new-era/

    GP 2.2.2 and GPP 1.7.7 are pretty old. You may want to consider updating them.

    A wise man once said:
    "Have you cleared your cache?"

    #1492699
    vast

    Thanks Elvin. That’s great.

    #1494708
    Elvin
    Customer Support

    No problem. 🙂

    A wise man once said:
    "Have you cleared your cache?"

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.