patric-boehner
9/24/2017 - 7:09 PM

Adds a small inline script to append `js` class to body tag if JavaScript is enabled in Genesis theme

Adds a small inline script to append js class to body tag if JavaScript is enabled in Genesis theme

<?php

/**
 * Script sample comes from WP SiteCare's carelib
 * https://github.com/wpsitecare/carelib
 *
 * A simplified version of Gary Jones Genesis JS
 * https://github.com/GaryJones/genesis-js-no-js/
 *
 * This produces what the Genesis Sample Theme does in the
 * 'responsive-menu.js' but moves it to a small inline script that
 * is added after the opening <body> tag.
 * Unlike Gary's sample i've skipped adding a no-js body tag as the
 * Genesis Sample Theme does not include it and all styles tied to a
 * JS interaction are styled with .js
 * 
 * If you use this action, you will need to go into 'responsive-menu.js'
 * and remove line 6 '$( 'body' ).addClass( 'js' );'.
 *
 */

// Add JS after opening <body> to append .js to body tag in Genesis
add_action( 'genesis_before', 'pb_add_js_body_class' );
function pb_add_js_body_class() {

	echo '<script type="text/javascript">document.body.classList.add("js");</script>' . "\n";

}