Dump defined variables for a quick look at what’s available in the current context

Templating in WordPress is pretty easy, right? There are loads of template functions and most things are pretty well document but every now and then it’s just nice to see exactly what variables you have at your fingertips.

All it takes a simple one-liner to do exactly that:

<?php
var_dump(get_defined_vars());

The above will dump an array of variables that you have available to you. The variable names are the keys and the value are…well….the values!

You might not see this in a nicely formatted way, however. If that is the case, simply wrap that baby up in some <pre> tags and you should be good to go:

<?php
echo '<pre>';
var_dump(get_defined_vars());
echo '</pre>;

Need a website? Let's talk.

From website design & SEO through to custom WordPress plugin development. I transform ideas into dynamic, engaging, and high-performing solutions.
Subscribe to get the latest insights & updates in the world of web and how it impacts your business and website.
© 2024 Phil Kurth  |  All rights reserved.