Technically possibly, but probably not worth the effort (and overhead). If you inspect the source with something like Developer Tools in Chrome, your HTML will be automatically indented. In fact, some caching plugins (like W3 Total Cache) even remove all whitespace to improve page load times.
That said, if you want to ensure that your wp_head
content is indented, you would need to do the following:
- Add a function to
get_header
which executes last. This function get all functions attached towp_head
(using$wp_filter['wp_head']
), remove them, and reattach them to your own custom action (my_wp_head
for example). - A custom function (
my_wp_head() for example
) should then be attached towp_head
- In the
my_wp_head()
function you would want to- Create an array of match/replace regex patterns (
$patterns = array("pattern"=>"replace pattern");
). This pattern should trim whitespace and re-add tabs to the beginning of each line. - Make a call to
ob_start()
to capture output - Process the previous
wp_head
functions by callingdo_action('my_wp_head')
- Process output with a call to
echo preg_replace( array_keys($patterns), array_values($patterns), ob_get_clean() );
- Create an array of match/replace regex patterns (