Closed salcode closed 8 years ago
Another alternative to using language attributes method
add_filter('body_class', 'genesis_javascript_detection_body_class');
add_action( 'genesis_before', 'genesis_javascript_detection_script', 1 );
function genesis_javascript_detection_body_class($classes) {
$classes[] = 'no-js';
return $classes;
}
function genesis_javascript_detection_script() {
echo "<script>document.body.className=document.body.className.replace(/\bno-js\b/,"js");</script>\n";
}
@bryanwillis
The filter on body_class
adds the no-js
class on the body
element rather than html
element. While that seems like it would work, adding no-js
to the html
element seems to be the standard.
Examples
You're right that it makes more sense to add the JavaScript with a hook rather than hardcoding in the header. I've updated the PR. Thanks.
Looks like you've been busy sal :+1:
@bryanwillis thanks for all the time you've put into these items previously. I'm just trying to catchup :grinning:
See http://www.paulirish.com/2009/avoiding-the-fouc-v3/
@bryanwillis wrote the following about this in #127
Add no-js class using wordpress filters. This makes it much easier to remove since all that's needed is
remove_filter( 'language_attributes', 'bsg_js_detection_lang_atts' );
. Plus now we no longer have to hardcode the head which makes language attributes available again and the ability to add schema markup to the head (<head itemscope itemtype="http://schema.org/WebSite">
). Also, the current way we have it isn't doing any html5 check like the rest of the theme does and is also addinglink rel='profile'
to the head tag which is the wrong way to do it in html5.