WordPress Debugging Guide

Did you know that WordPress provides a number of debugging tools for you? These are especially useful for theme and plugin developers. We can also find some plugins which can be helpful in debugging our WordPress code. In this post we take a look at WordPress in-built features as well as some great plugins for debugging.
Table of Contents

Sponsored Ad

If you purchase through a link on our site, we may earn a commission.

Did you know that WordPress provides several debugging tools for you? These are especially useful for theme and plugin developers. We can also find some plugins which can help debug our WordPress code. If you’re interested in monitoring tools please take a look at our review of WordPress monitoring plugins.

Let’s take a look at what WordPress provides as a standard first.

In-Built WordPress Debugging Features

The features below are all built into the WordPress standard installation and can be easily activated when needed.

WP_DEBUG

WP_DEBUG is a WP constant that is found in the wp-config.php file. Once you define it in wp-config.php you’ll start seeing PHP notices and also WordPress-generated debug messages, particularly deprecated function usage. To activate this feature, open the wp-config.php file and enter the following at the end of the file:

[php]define(‘WP_DEBUG’, true);[/php]

There’s also WP_DEBUG_DISPLAY and WP_DEBUG_LOG, which enable you to log notices generated by WP_DEBUG to a wp-content/debug.log file.

WP_DEBUG should not be used on a live site.

WP_DEBUG will often reveal potential problems in your code, such as unchecked indexes (empty() and isset() are your friend) and undefined variables. (You may even find problems in WordPress itself, in which case you should file a bug report.)

You can also put the following code into your theme’s functions.php file to enable WP_DEBUG:

[php]if (!defined(‘WP_DEBUG’)) define(‘WP_DEBUG’, true);[/php]

SAVE_QUERIES

The WordPress database class can be told to store query history:

[php]define( ‘SAVEQUERIES’, true );[/php]

When this is defined, $wpdb->queries stores an array of queries that were executed, along with the time it takes to execute them.
The database class has additional error and debugging tools, which are documented on the Codex (though when in doubt, check the source).

SCRIPT_DEBUG

In the admin, WordPress minimizes and concatenates JavaScript and CSS. But WP also comes with the β€œdevelopment” scripts, in the form of dev.js and dev.css. To use these instead:

[php]define( ‘SCRIPT_DEBUG’, true );[/php]

WP Crontrol

WP Crontrol is a WordPress plugin designed to give you detailed control over your website’s WP-Cron system. It allows you to view, edit, add, and manage cron events and schedules, providing insights into scheduled tasks and their execution.

The plugin supports timezone awareness, alerts for misfiring events, and offers a privacy-focused approach, ensuring no data is sent to third parties. WP Crontrol is a valuable tool for developers and website administrators seeking to optimize and debug scheduled tasks within WordPress​​.

Activity Log

The Activity Log plugin for WordPress is a comprehensive solution for monitoring and tracking all activities on your WordPress site. It acts like a black box, recording every action in the WordPress admin area, allowing you to see what users are doing on your site in an activity log.

This plugin is especially useful for identifying unauthorized activities, tracking post publications, and monitoring plugin/theme changes. It’s designed to operate efficiently without affecting site performance and supports GDPR compliance by providing tools for data export and erasure.

Ideal for website administrators looking to secure their site and maintain an audit trail of user actions​​.

Do you use any other tools? Let us know!

Jean Galea is an investor, entrepreneur, and blogger. He is the founder of WP Mayor, the plugins WP RSS Aggregator and Spotlight, as well as the Mastermind.fm podcast. His personal blog can be found at jeangalea.com.

Sponsored Ad

If you purchase through a link on our site, we may earn a commission.

All suggestions are anonymous.

More from our blog...

One Response

  1. Useful development tools. I especially like the Debug Objects. Black Box used to be my favorite, but I don’t like that debug messages are shown to non-admin users.

Post a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Stay updated with WP Mayor's newsletter showcase every week

Stay on top of every new WordPress innovation and latest launches. Receive all our fresh product reviews and expert guides directly in your inbox.

Hosting Survey 2024

Are you happy with your hosting provider or are you over-paying for too little? Have your say below!

"*" indicates required fields

What's the main reason you picked this host?*
How happy are you with your host?*

OPTIONAL: If you'd like to receive the results of this survey, please enter your details below.