Skip to content

Instantly share code, notes, and snippets.

@damiencarbery
Last active August 25, 2019 16:47
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 damiencarbery/a9a21db76f61a53554c3ea2fee658638 to your computer and use it in GitHub Desktop.
Save damiencarbery/a9a21db76f61a53554c3ea2fee658638 to your computer and use it in GitHub Desktop.
HTML comments may not work for debugging - Debug comments may not appear in markup if the page is minified. https://www.damiencarbery.com/2019/08/html-comments-may-not-work-for-debugging/
<?php
/*
Plugin Name: Debug with comments
Plugin URI: https://www.damiencarbery.com/2019/08/html-comments-may-not-work-for-debugging/
Description: Debug using html comments.
Author: Damien Carbery
Version: 0.1
*/
// This div *will* be removed during html minification.
add_action( 'wp_footer', 'dcwd_footer_debug_with_comments' );
function dcwd_footer_debug_with_comments() {
echo '<!-- Page ID: ', get_the_id(), ' -->';
}
<?php
/*
Plugin Name: Debug with hidden div
Plugin URI: https://www.damiencarbery.com/2019/08/html-comments-may-not-work-for-debugging/
Description: Debug using hidden div instead of html comments.
Author: Damien Carbery
Version: 0.1
*/
// This div will *not* be removed during html minification.
add_action( 'wp_footer', 'dcwd_footer_debug_with_hidden_div' );
function dcwd_footer_debug_with_hidden_div() {
echo '<div style="display:none">Page ID: ', get_the_id(), ' </div>';
}
<p class="first-p">This is the first paragraph.</p><p class="last-p">This is the last paragraph.</p>
<!-- Comment before the content -->
<p class="first-p">This is the first paragraph.</p>
<!-- A comment in the middle -->
<p class="last-p">This is the last paragraph.</p>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment