Skip to content

Instantly share code, notes, and snippets.

@nickdavis
Created February 28, 2017 10:29
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickdavis/73d91d674b843b77a1cd0a21f9c0353a to your computer and use it in GitHub Desktop.
Save nickdavis/73d91d674b843b77a1cd0a21f9c0353a to your computer and use it in GitHub Desktop.
Add 'no-js' class to <html> tag in WordPress in order to work with Modernizr
<?php
add_filter( 'language_attributes', 'add_no_js_class_to_html_tag', 10, 2 );
/**
* Add 'no-js' class to <html> tag in order to work with Modernizr.
*
* (Modernizr will change class to 'js' if JavaScript is supported).
*
* @since 1.0.0
*
* @param string $output A space-separated list of language attributes.
* @param string $doctype The type of html document (xhtml|html).
*
* @return string $output A space-separated list of language attributes.
*/
function add_no_js_class_to_html_tag( $output, $doctype ) {
if ( 'html' !== $doctype ) {
return $output;
}
$output .= ' class="no-js"';
return $output;
}
@Ninetheme
Copy link

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment