Pretty-printing Wordpress HTML output for development purposes
Asked Answered
B

2

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.

Bahaism answered 20/8, 2010 at 16:9 Comment(6)
Well, firebug does provide you with indentation in it's html tab.Tannenwald
This is better suited to wordpress.stackexchange.comEvangelinaevangeline
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.Evangelinaevangeline
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.Gametophyte
I sometimes use this technique but that involves copy-pasting the code, creating a new document to paste it into, etc.Bahaism
possible duplicate of How to properly indent PHP/HTML mixed code?Pavyer
I
0

I suggest:

  1. Get Firebug
  2. Use PHP heredocs
  3. Include whitespace in your output using \n (newline), \t (tab), etc.
Interline answered 20/8, 2010 at 16:28 Comment(1)
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()).Bahaism
F
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);
Fulgurite answered 18/4, 2017 at 4:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.