Send values of variables to a debug file with a simple function call.

When developing a plugin or function, its often useful to be able to read variables at critical points in your code. Or, to log important events over a number of days.

Calling this function, allows you to send variables or messages into a text file in your uploads folder. Every message sent to this debug file is timestamped and added to the top of the file. Once the file becomes very large, it is automatically trimmed.

The Code


It’s very simple to use. There are several examples below. Note, that you must serialize arrays.

To read the debug file, you can view it in your browser, as can anyone else. Please don’t store any sensitive data in the file! Point your browser at – ‘<YOUR URL>/wp-content/uploads/debug.txt’.


add_to_debug('Some code section ran');
if ($condition === true) add_to_debug('Something occurred message');