Make WordPress Core

Changeset 31184


Ignore:
Timestamp:
01/15/2015 11:09:07 PM (10 years ago)
Author:
lancewillett
Message:

Twenty Fifteen: move js and no-js class name functionality out of header template and into a wp_head hook in functions.php file so that the JavaScript functionality isn't hard-coded into a template file.

Fixes #30770, props chipbennett, valendesigns, and peterwilsoncc.

Location:
trunk/src/wp-content/themes/twentyfifteen
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-content/themes/twentyfifteen/functions.php

    r31182 r31184  
    195195
    196196/**
     197 * JavaScript Detection.
     198 *
     199 * Adds a `js` class to the root `<html>` element when JavaScript is detected.
     200 *
     201 * @since Twenty Fifteen 1.1
     202 */
     203function twentyfifteen_javascript_detection() {
     204    echo "<script>(function(html){html.className = html.className.replace(/\bno-js\b/,'js')})(document.documentElement);</script>\n";
     205}
     206add_action( 'wp_head', 'twentyfifteen_javascript_detection', 0 );
     207
     208/**
    197209 * Enqueue scripts and styles.
    198210 *
  • trunk/src/wp-content/themes/twentyfifteen/header.php

    r30897 r31184  
    1919    <script src="<?php echo esc_url( get_template_directory_uri() ); ?>/js/html5.js"></script>
    2020    <![endif]-->
    21     <script>(function(){document.documentElement.className='js'})();</script>
    2221    <?php wp_head(); ?>
    2322</head>
Note: See TracChangeset for help on using the changeset viewer.