Right now all the stuff that gets included in wp_head are left justified all the way in the code view.
Whereas all my other code that is around the wp_head is indented (tabbed) two times. Is it possible to add an indent/tabs to all the wp_head info?
Thanks
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: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).my_wp_head() for example
) should then be attached towp_head
my_wp_head()
function you would want to$patterns = array("pattern"=>"replace pattern");
). This pattern should trim whitespace and re-add tabs to the beginning of each line.ob_start()
to capture outputwp_head
functions by callingdo_action('my_wp_head')
echo preg_replace( array_keys($patterns), array_values($patterns), ob_get_clean() );
You can solve it with creating a custom function inside “functions.php”:
Now you just need to call this function in the “header.php”:
If you want to use it for
wp_footer()
too, you can create this function for general usage in “functions.php”:And call it in “header.php” or “footer.php” like
A better way, to avoid indenting lines that are already indented which some seem to be
Use http://wordpress.org/plugins/wp-minify/. It will merge css, js & html + remove useless comments. Your page speed will be improved, and all HTML code in the source will be compacted.
Problem solved, I guess!
As additions we can specify the number of tabs for html blocks that need more than one tab and use parameters for the functions.
Before
After: