Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress WordPress Customizer API Native WordPress Customizer Settings The customize_register Action Hook

var_dump unformatted output

I ran into an issue while following along with the video here:

In the video, the output of the var_dump command appears nicely formatted in Zac's WP Customizer screen. However, in my WP Customizer the output appears as a solid block of unformatted text, no spaces or line breaks.

I tested this in FF, IE, and Chrome (as well as with another theme) and had the same results every time.

I (partially) solved this by echoing out some pre tags (and applying some styling for legibility) as so:

echo '<pre style="background: #DEDEDE; color: #484848;">'; 
var_dump( $wp_customize ); 
echo '</pre>';

What I'm wondering is, how is Zac setup to show that well formatted output by default without needing to pre the output for legibility?

Tammy Dotson
Tammy Dotson
16,790 Points

I am having the same problem and even with your settings am having trouble following exactly where he is at, although it does make it much better I would like to know the answer to this as well.

Thanks Tammy for letting me know I'm not alone in the issue.

I edited my post to indicate I consider this a partial fix as I, like you, still find the result less useful than what appears on Zac's screen.

In addition to where line breaks are inserted, Zac's output also seems to be doing some color-coding. This is what makes me wonder if this is related to his development environment.

9 Answers

Thanks for the reply Zac. It doesn't looks like var_export or JSON View is the trick. At least for me on a MacBook Pro with Yosemite/Chrome/MAMP (3.0.7.3 with PHP 5.6.2).

Any chance you're running XDebug on your dev server? And/or is your local environment "stock" MAMP?

Thanks again for all the great WP Courses :)

Niki Papageorgiou
Niki Papageorgiou
2,270 Points

ok... same problem hier... local server and online server

ok... the solution for me is... :

function wpt_register_theme_customizer( $wp_customize ) {

echo '<pre>';
var_dump( $wp_customize );  
echo '</pre>';

}

add_action( 'customize_register', 'wpt_register_theme_customizer' );

and i believe that will work for all... at least i hope anyway... :-)

ty michael and Giuseppe Elia!

Craig Watson
Craig Watson
27,930 Points

Super Helpful to find this at the bottom :), allowed me to at least follow along and understand what was happening without all sorts of downloads and extensions!

Robert Bepko
Robert Bepko
2,837 Points

Sweet. Though 2 years later, thanks @Niki P. Mine displays just like Zak now. For others having trouble, my config was using MAMP 4.06 with both Chrome Version 56.0.2924.87 (64-bit). Just copy/paste replacing var_dump line. Easy.

Zac Gordon
STAFF
Zac Gordon
Treehouse Guest Teacher

Oh wow, sorry folks. I wonder if this is because of a chrome browser extension called "JSON View" that I have installed? Other than that I'm not doing anything special.

Adding the pre tags can definitely help with output though as well. You may also try using var_export, which is a little cleaner.

I tested out both of those and didn't see any change (I'm on Windows 8 & XAMPP here if that matters).

Thanks very much for the suggestions though! Could Wordpress have done anything different on their end in regards to an update that would effect either the customizer or the behaviour of var_dump since you recorded that?

Thanks for these lessons, btw! Your Wordpress Development track has changed WP from something I dreaded having to touch, to a far more comfortable experience. I enjoy your teaching style and look forward to more from you this year.

EDIT: I enabled XDebug per Jason's response below. I don't know if that is exactly what you are using, but the output was close enough for me!

Chad Passaro
Chad Passaro
1,089 Points

Zac, Is there anyway to find out how you got this formatted in this way. I tried adding "JSON view" and the solutions below seem complicated. If there is nothing really special may you can let us know how you got it that way. Thanks in Advance

Thanks for the link, though ex3v's answer as referenced is identical to what I posted above (minus the optional style rules).

The main thrust of the question though is that Zac was able to achieve his formatting without any additional syntax beyond

var_dump( $wp_customize );

He also appears to have some syntax based color coding happening.

He may be using a WP debug plugin or he may have something else going on, hence the question. What he's got looks nice, clean, and minimal. I would love to be able to replicate it.

Just chiming in that y'all aren't alone.

Jason, I don't know if XDebug is what Zac was using, but it did the trick for me!

I actually went to install that per the instructions on the site you linked, only to discover that the XAMPP package I used already includes that by default (I had only to remove a '";" disabling it in the php.ini file). The output was now color coded and formatted.

Thanks alot for the link! I'm going to mark your post as 'best answer' as that solved the issue for me.

For anyone using DesktopServer to create local testing domains:

navigate to php.ini in the xampplite/php/ directory and open it in your text editor of choice at the very end of the file you will see a code block that says:

[XDebug]
;zend_extension = "c:\xampplite\php\ext\php_xdebug.dll"
xdebug.remote_enable =on
xdebug.remote_handler = "dbgp"
xdebug.remote_host = "127.0.0.1"
xdebug.trace_output_dir = "c:\xampplite\tmp"
xdebug.report_port=9000

Simply remove the semicolon at the beginning of "zend_extension" to enable functionality

For any others This Page at the XDebug site allows you to paste the output of phpinfo() and will give you tailored instructions to enabling the features.

Thanks, Jason!

Tammy Dotson
Tammy Dotson
16,790 Points

This worked for me also, thanks guys!

For anyone using MAMP PRO and having the problem described above you need to ensure PHP debugging is enabled just go to the 'Main Window' then select the PHP tab and then check the 'Debugger:' check box. Then you won't require any further code and you can operate it exactly as Zac does in his example.

Christopher Estes
Christopher Estes
1,132 Points

Using latest version of MAMP Pro. Clicked PHP under "Languages" in the left sidebar. Checked Xdebug in main window. Issue resolved.