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.
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.
You must be logged in to post a comment.
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 thelang=en
string, for ex. You can hook to that and replace the string with your CSS class, like this:This works only when your theme follows the WordPress Theme Development Checklist. Sometimes people don’t follow this and that breaks the technique.
A little late to the game here, but just to add to @Rilwis answer you could add the script to a function that checks if the
no-js
language attributes are added or not.While I don’t use Modernizr, I do use the no-js detection script from twenty-sixteen so inclusion is pretty much the same. Doing it this way, you don’t have to worry about removing the function added to
wp_head
orwp_enqueue_scripts
since it happens automatically when you remove the filter.Adding Removing Filter Approach
Theme Support Approach
Another option could be to do this using
current_theme_supports
.