Skip to content

Instantly share code, notes, and snippets.

@keithdevon
Created March 27, 2018 09:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keithdevon/1fbedcfe48fc0de03c88c5e191822eea to your computer and use it in GitHub Desktop.
Save keithdevon/1fbedcfe48fc0de03c88c5e191822eea to your computer and use it in GitHub Desktop.
Function to append a grid overlay div to the body depending on the environment
<?php
/**
* This function appends a grid overlay div to the body depending on the environment.
*
*/
function tgf_add_grid_overlay_debugging_helper() {
if ( WP_LOCAL ) {
// echo the script
echo '<script>
function toggleVisualGrid() {
var element = document.getElementById("grid-overlay-js");
element.classList.toggle("is--visible");
}
</script>';
// echo the div
echo '<div id="grid-overlay-js" class="grid-overlay"><div class="grid-overlay__inner"></div></div><button onclick="toggleVisualGrid()" class="button grid-overlay-toggle">Show grid</button>';
}
}
add_action( 'wp_footer', 'tgf_add_grid_overlay_debugging_helper' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment