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:
- Add a function to
get_header
which executes last. This function get all functions attached to wp_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 to wp_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 calling do_action('my_wp_head')
- Process output with a call to
echo preg_replace( array_keys($patterns), array_values($patterns), ob_get_clean() );