The instructions for implementing Modernizr state that I should add class="no-js"
to the <html>
element.
Is there a way to do this in WordPress using a hook or filter? If at all possible, I’d prefer to do this without editing the theme files.
2 Answers
This is not exactly the answer, but you can use a hook for language_attributes
filter. This action is fired at <html>
tag and what it does is simply echo the lang=en
string, for ex. You can hook to that and replace the string with your CSS class, like this:
add_filter('language_attributes', 'modernizr');
function modernizr($output) {
return $output . ' class="no-js"';
}
This works only when your theme follows the WordPress Theme Development Checklist. Sometimes people don’t follow this and that breaks the technique.