Results 1 to 1 of 1
  1. #1
    universal4's Avatar
    universal4 is online now Forum Administrator
    Join Date
    July 2003
    Location
    Courage is being scared to death...and saddling up anyway. John Wayne
    Posts
    32,770
    Thanks
    4,055
    Thanked 8,864 Times in 5,668 Posts

    Default Wordpress Filter for html 5 support

    /Geek Alert

    After PROFRBcom and I were discussing w3c validation errors the other day I took a deeper look at one of my sites with an older theme on it to see what the results were.

    Beside fixing stupid little things like open tags and typos in opening or closing tags I got the site down to a handful of errors from the theme itself.

    The most common errors then became
    Code:
    <script type="text/javascript"
    warnings.
    The type attribute is unnecessary for JavaScript resources.
    There were also some style errors, but they were also due in part to
    Code:
     type='text/css'>
    After some digging I found it was from html 5 standards, and that type is obsolete.

    I figured this might be handy for those that might be using older themes and have no interest in changing their themes or trying to rewrite too much of the theme function admin and include files.

    I discovered all that was needed was adding a filter to the functions file that added html 5 support to the theme.

    Obviously, be sure to make a backup BEFORE attempting any functions file changes, a typo in there breaks the site.
    The functions.php file will always be in the root folder of the theme. /wp-content/themes/joescasinotheme/functions.php

    Filter to add:
    Code:
    add_action(
        'after_setup_theme',
        function() {
            add_theme_support( 'html5', [ 'script', 'style' ] );
        }
    );
    I am not 100% sure if placement makes a difference, but felt it was best suited after if statements and also after theme_include_lib statements.

    Not everyone agrees with me but I feel better restarting the site after a functions file change, but the function file should be read with every page load.

    I certainly want to give credit to where I got this answer. Stackexchange has been a great help to me over the years, and they have a ton of sub domains for many things tech related.
    https://wordpress.stackexchange.com/...d-by-wordpress

    For those interested there are a few solutions listed on that page, and a tiny bit of debate surrounding them. The below is why you always want to study various answers. One answer would slow down page rendering.

    A few of the solutions use preg_replace()
    it isn't very efficient. You'd be running preg_replace() on the entire "final" output from Wordpress before it gets sent to the client's browser, for every request.
    Reminder, make a backup before changing the file.

    Rick
    Universal4

  2. The Following 2 Users Say Thank You to universal4 For This Useful Post:

    chaumi (24 July 2022), newcustomeroffer (24 July 2022)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •