Skip to content

Instantly share code, notes, and snippets.

@srikat
Last active October 29, 2016 01:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save srikat/fe17b427861105c930b5543f78391ce3 to your computer and use it in GitHub Desktop.
Save srikat/fe17b427861105c930b5543f78391ce3 to your computer and use it in GitHub Desktop.
How to automatically add browser class to html in WordPress. https://sridharkatakam.com/automatically-add-browser-class-html-wordpress/
// Enqueue Scripts
add_action( 'wp_enqueue_scripts', 'sk_enqueue_scripts' );
function sk_enqueue_scripts() {
wp_enqueue_script( 'detect', get_stylesheet_directory_uri() . '/js/detect.min.js', '', '1.0.0', true );
wp_enqueue_script( 'general', get_stylesheet_directory_uri() . '/js/general.js', '', '1.0.0', true );
}
jQuery(function( $ ){
var ua = detect.parse(navigator.userAgent);
$('html').addClass(ua.browser.family.toLowerCase());
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment