Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

share|improve this question
2  
Why does this matter? –  Wyck Aug 5 '13 at 23:23
    
It's perhaps a little OCD, but I think WP devs should have complete control over markup output. –  jnthnclrk Aug 7 '13 at 9:58

2 Answers 2

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:

  1. 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).
  2. A custom function (my_wp_head() for example) should then be attached to wp_head
  3. In the my_wp_head() function you would want to
    1. 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.
    2. Make a call to ob_start() to capture output
    3. Process the previous wp_head functions by calling do_action('my_wp_head')
    4. Process output with a call to echo preg_replace( array_keys($patterns), array_values($patterns), ob_get_clean() );
share|improve this answer
    
I would love to see this as something I could use in functions.php. –  jnthnclrk Aug 5 '13 at 15:49
    
@jnthnclrk As you might have read on the help center, "do this job for me questions are out of scope". Even with bounty attached. –  kaiser Aug 12 '13 at 10:13
    
Ah, come on. That's no fun! –  jnthnclrk Aug 14 '13 at 20:50
    
So fwiw, you can use that in functions.php, however since I'm an IT consultant it wouldn't make much sense for me to just do it for you... I wouldn't want to deprive you of the learning experience :P –  doublesharp Aug 14 '13 at 23:44
    
I have tried and failed. –  jnthnclrk Aug 22 '13 at 17:08

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!

share|improve this answer
    
Not really I'm looking for a clean function filter to add tabulation to wp_head(). –  jnthnclrk Aug 7 '13 at 9:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.