6

Is there a simple way (plugin / function) that uses Tidy or some other lib to pretty-print Wordpress's HTML output?

It's unreadable as it is and it's almost impossible to write a theme with proper indentation with all the includes / hooks going on all over the place.

Performance is not an issue as this only needs to be active for development purposes.

Andrei
  • 1,606
  • 4
  • 19
  • 31
  • Well, firebug does provide you with indentation in it's html tab. – mhitza Aug 20 '10 at 16:18
  • This is better suited to wordpress.stackexchange.com – Bobby Jack Aug 20 '10 at 16:47
  • Note that firebug's HTML view is dynamic - i.e. it will update according to any DOM manipulation. Depending on your requirements, and whether your page has any scripts present, this may be an issue. – Bobby Jack Aug 20 '10 at 16:48
  • If you need it static I suppose he could just copy n' paste the source from 'view source' over to an IDE and have that format the code for him. – Yi Jiang Aug 21 '10 at 05:14
  • I sometimes use this technique but that involves copy-pasting the code, creating a new document to paste it into, etc. – Andrei Aug 23 '10 at 23:13
  • possible duplicate of [How to properly indent PHP/HTML mixed code?](http://stackoverflow.com/questions/1155799/how-to-properly-indent-php-html-mixed-code) – Gajus Feb 22 '14 at 12:44

2 Answers2

0

I suggest:

  1. Get Firebug
  2. Use PHP heredocs
  3. Include whitespace in your output using \n (newline), \t (tab), etc.
Ian McIntyre Silber
  • 5,553
  • 13
  • 53
  • 76
  • I do have Firebug. Problem is not with stuff from variables but more of the way things from core Wordpress get included (eg. get_header(), get_footer()). – Andrei Aug 23 '10 at 23:10
0

Give Kint PHP Debugger a try.

Works great for doing var_dumps with a nice UI.

Example:

$items = array('pine', 'apple', array('numbers' => [1,2,3,4]));
d($items);
Rick
  • 12,606
  • 2
  • 43
  • 41