All You Need to Know About WordPress Debugging

by | Last Updated Jan 3, 2021 | WordPress | 0 comments

In an ideal world, you’d never have to debug any issues. In the real world, you’re almost always going to encounter WordPress site problems that require a more in-depth examination.

WordPress has a built-in debug mode that helps you do this. Also, you can find useful third-party tools to help you troubleshoot WordPress.

In this post, we’ll explore how to enable WordPress’ built-in debug mode. We’ll also share some other methods of debugging your WordPress site.

What Can WP Debug Do for You?

WordPress’s core software, plugins, and themes are written in PHP.

WordPress debug mode displays all PHP errors, error notices, and warnings, so you can figure out what’s wrong.

When you enable debug mode, you’ll see error messages whenever there is a problem.

You can then either resolve the issue or contact your developer or the theme/plugin developer.

What Is a WordPress Debug Log?

You’ll see such messages on your site at the moment when you enable WordPress to debug mode. But those messages aren’t saved anyplace.

If you wish to save them, you may enable the WordPress debug logs to keep a copy of them on your server.

When WordPress is configured with the WP_DEBUG_LOG constant set to true, it writes all errors to wp-content/debug.log.

However, you can also write the log to a customized folder on your server.

Suppose you want to log problems but do not wish to display them publicly in the HTML of your page.

In this case, you can also use the WP_DEBUG_DISPLAY constant. This will ensure that the debug mode is enabled but will not display error messages.

How to Enable Debug Mode in WordPress?

There are several ways to enable the debug mode in WordPress. We’ll cover two ways to activate it.

Using a WordPress Debug Plugin

You can find free plugins for WordPress that make it easy to enable the debug mode. Several options are available at WordPress.org. But we recommend Andy Fragen’s free WP Debugging plugin.

Wp Debugging Plugin in the WordPress Directory

The plugin will start working right away after you install and activate it. By default, it sets these constants to true. That means it enables the features listed below.

  • WP_DEBUG – enables the debug mode.
  • WP_DEBUG_LOG – logs messages.
  • SAVEQUERIES
  • SCRIPT_DEBUG

We’ll discuss what the last two constants do later.

WP Debugging Settings Page

Please go to the Tools > WP Debugging page to configure a few options.

Once finished, make sure you turn off debug mode by disabling the plugin.

How to Enable WordPress Debug Mode Manually

Finally, if you know the WordPress debug mode constants, you can manually add them to your wp-config.php file.

To begin, log in to your server via SFTP or DirectAdmin File Manager and edit wp-config.php. By default, the wp-config.php file is in the root directory of your website.

Add the following code snippet above the line that says /* That’s all, stop editing! Happy publishing. */ to enable just the primary WordPress debug mode.

define( 'WP_DEBUG', true );

The following constants can also be used, depending on your preferences.

define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );

Once you’re done, you can remove the snippet or set the constants to false to remove debug mode.

Once You’re Finished, Make Sure to Turn off Debug Mode in WordPress

The debug mode is useful when troubleshooting WordPress issues.

However, please don’t leave it enabled 24/7 because it can reveal sensitive information from your PHP code to website visitors.

We mentioned it above – but this is only a reminder to turn off debug mode once you’re done with your troubleshooting.

Other Ways of Debugging WordPress

Additional to the built-in debug tool mentioned above, several third-party and built-in tools allow you to debug WordPress sites.

Script Debugging

SCRIPT_DEBUG is a built-in constant that makes WordPress use the dev versions of core JS and CSS files rather than the minified versions. These are the standard versions of core files that WordPress usually loads.

If you require testing changes to the built-in .js or .css files, this can be very helpful.

To activate SCRIPT_DEBUG, you may either:

  1. Use the free WP Debugging plugin, which turns it on by default.
  2. Add this constant to your wp-config.php file.
define( 'SCRIPT_DEBUG', true );

Debugging Database Queries

If you’re experiencing database issues with your site, use the SAVEQUERIES constant to enable database query logging.

This will help you to track:

  • Each query in the database.
  • The function that invoked the database query.
  • How long it took to run the query.

You can enable query logging in two ways:

  1. Use the free WP Debugging plugin, which turns it on by default.
  2. Add this constant to your wp-config.php file.
define( 'SAVEQUERIES', true );

Note: Using this on a production site will negatively affect its performance. So use it on a staging site whenever possible and disable it once you’re done.

Query Monitor WordPress Plugin

The Query Monitor plugin helps debug WordPress in many areas, including:

  • User capabilities
  • Block editor blocks
  • Hooks and actions
  • PHP errors
  • Database queries
  • Enqueued scripts and style sheets
  • HTTP API calls

Overall, it’s one of the finest WordPress debug tools that you’ll get, which is why almost all its reviews have been Five stars.

Query Monitor Plugin in WordPress Directory

When the plugin is activated, the WordPress toolbar will show new options that display debug information.

Query Monitor Overview Screen

When clicked, Query Monitor opens a new window with more details.

Summary

WordPress has a built-in debug mode for viewing PHP errors and notices.

You can enable it by modifying your site’s wp-config.php file or by installing plugins.

Query Monitor is a free plugin that provides more help besides the built-in tools.

Would you like to know more about WordPress debugging? Let us know if you have any questions!

We engineered our cloud infrastructure with Performance, Speed, Scalability, and Security in mind.

That’s why we built Rovity with AWS, CloudLinux OS, DirectAdmin, and LiteSpeed Web Server.

Come and experience the next generation of shared hosting on the cloud

By Jafar Muhammed

Jafar Muhammed has 10+ years of experience in WordPress, web hosting, domain names, DNS, CDN, server administration, etc. He is an open web advocate. He is the CEO of Rovity, the fastest growing premium shared hosting startup in India.

Check Out These Related Posts

Avoid These 8 Blogging Mistakes in 2021

Avoid These 8 Blogging Mistakes in 2021

Blogging plays a large part in the $400 billion content marketing industry. Blogs are an excellent way to make substantial extra income. They're also powerful tools for generating traffic to your website. Blogging isn't just a part-time gig and a digital marketing...

read more

0 Comments

0 Comments

Submit a Comment

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