Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.