WordPress Debug: Complete Guide for Beginners

Probably there is no such thing as perfect code and it is every webmaster’s nightmare when their sites or . So today we are going to show you tips on how to use WordPress Debug and other WordPress debugging methods that will help you deal with things that may be out of your control.

What does “debugging” or “debug” mean?

Debugging, in Spanish is debugging, and it means identifying and eliminating errors or problems in your code. The last step of debugging is to test the correctness of the code and make sure the problem doesn’t happen again.

This is mostly done by developers using debugging tools, and is part of a routine in the software development stage.

The debugging process can be done using strategies like unit testing, code review, and pair programming.

So before code or software is released to users, developers will try to find any issues, then isolate and fix them.

Sometimes fixing the code can be a real headache as it can take more time than writing the code itself.

Practical uses of WP DEBUG

Having explained the general idea of ​​what WordPress Debug is, we are now going to cover the practical use.

WP_DEBUG

WP_DEBUG is found in the file wp-config.php and by default it has the value set to «fake«. If you want to enable it, you need to change it to «real«. To do this, you will need an FTP client, such as or a file manager to access the file.

In our example, we will use the File Manager of .

  1. Find the file wp-config.php in the root folder of your website. In our example, it is in -dev-9.xyz/public_html/wp-config.php.
  2. Open it and look for define(‘WP_DEBUG’, false)
  3. Once located, change false by true. Then save the file.

If you don’t find this code in your file wp-config.phpyou can add it above the line «/* That’s all, stop editing! Happy blogging. */«.

Please note that debugging should not be enabled on a website that is live because this mode is designed for development purposes only.

WP_DEBUG_LOG

By enabling WP_DEBUG_LOG, users can save all errors to a file debug.log. This function works hand in hand with WP_DEBUG and can help you reproduce issues for resolution.

See also  How to create a website with WordPress

To enable it, open the file wp-config.php and enter the following line below define(‘WP_DEBUG’, true);

define(‘WP_DEBUG_LOG’, true);

After activating the function, the file debug.log will be automatically saved in the folder /wp-content/ of your website. You can directly view the file in your browser.

WP_DEBUG_DISPLAY

You must disable WP_DEBUG_DISPLAY so that error messages are not displayed on your website.

By default, every time there is an error, it will be generated and displayed within your HTML code. And unlike WP_DEBUG, the original value is “true» and you should change it to «false» to hide all errors.

Or if it is not available, you should insert this line in the file wp-config.php, just below define(“WP_DEBUG”, true);.

define(‘WP_DEBUG_DISPLAY’, false);

All these features: WP_DEBUG, WP_DEBUG_LOG and WP_DEBUG_DISPLAY can be used at the same time to enable debugging, save a log file and hide all errors.

7 Tips for Debugging WordPress Issues

When your WordPress site crashes or has the white screen of death (WSoD), the common action is to disable plugins or check for updates.

While that is useful for looking for the culprit, it can be time-consuming, inefficient, and can also let the real problem go unnoticed. That’s why having the right tools can be a real game changer.

1. Enable WP_DEBUG

activation of WP-DEBUG is probably the easiest way to log issues on a WordPress site. But unfortunately, some developers don’t do this, probably because they forget that this feature exists.

We repeat it again, this time in a summarized way, WP_DEBUG is a constant that activates the “debug” mode in WordPress, and you can find it in the file wp-config.php. This constant can log all activities on your site and help you troubleshoot any issues.

We have covered more detailed instructions on WP_DEBUG above.

2. Enable WPDP Error Reporting

To catch any database related issues, you can enable WPDP error reporting.

the overall object $wpdb has a variable called $show_errors. And if you set it to true (true), you can have WordPress display SQL errors on the screen for any query.

To enable this, go to /public_html/wp-includes/wp-db.php and open the file. Search wpdb-class and change the variable $show_errors a true.

See also  How to Create an Affiliate Website? - Explanatory video

3. Check your website error logs

Sometimes you may come across the interval server error page when browsing your site. And to fix this problem, you can check the error logs of your website.

Doing a general check of the registry can help beginners and advanced developers to detect the website problem.

You can then use Google search to search for a possible solution.

4. Use the WordPress sandbox when modifying your code

If you want to minimize errors on your WordPress site, you can do so by first implementing the code in a .

A staging site is almost an exact clone of your live website and can be hosted on your private subdomain. This site acts as a development ground for any code you wish to implement on your live site.

This environment is not visible to visitors or search engines. So you can have more freedom to adjust and test the changes you want to implement, without affecting your live public site.

5. Enable SCRIPT_DEBUG

By default, WordPress uses the minified version of the files and JavaScript to help improve the load time of your site. However, this can be a problem because you can hide bugs in the scripts/plugins you use.

To change the execution of the script, WordPress also provides a constant that we can add to the file wp-config.phpnamely:

define( ‘SCRIPT_DEBUG’, true );

When the value is set to true, WordPress will automatically load the non-minified versions of all CSS and JavaScript files, causing all plugins to use their full version.

6. Detect PHP errors

You can catch errors early in your scripts using phpinfo. This file can output information about the current state of PHP, including build options and extensions, environment, OS version, HTTP headers, and license.

To do so, you can configure the file php.ini to enable error reporting. However, some hosting services, including Shared Hosting Plan, disable this option.

This is because you don’t have root access to enable the feature.

But instead you can use the , which provides you with a simple wizard to check your code for errors. And for a more thorough review, you can also use IDEs like or

See also  How to change a theme in WordPress

7. Take advantage of some debugging tools

If you need simplicity to monitor errors on your WordPress site, you can also take advantage of WordPress debugging plugins.

1.

This plugin provides a panel of tools for developers in WordPress. You can enable database queries, PHP errors, HTTP API calls, hooks and actions, stop editor blocks, queued scripts and style sheets, and more.

Alternatively, you can also use and to help you debug your WordPress site. However, these two plugins may have compatibility issues with the latest version of WordPress.

two.

You can also perform more robust debugging using a premium tool like New Relic. This app will help you monitor user experience, map WordPress architecture, analyze and improve site performance, and detect anomalies before they happen.

All of those features will help you collect data for troubleshooting so you can provide the best possible experience for your visitors. You can try New Relic for 14 days for free.

conclusion

These are all the tips you need to know about debugging a WordPress site. As a developer, you need to identify and fix problems before publishing any code or plugins to users. As a webmaster, you can also use debugging tools to identify the causes of performance issues on your website.

To debug your WordPress site, you can do the following:

  • Enable WP_DEBUG
  • Enable WPDP error reporting
  • Check your website’s error logs
  • Use the WordPress staging environment when modifying your code
  • Enable SCRIPT_DEBUG
  • Detect PHP errors
  • Use debugging tools like Query Monitor or New Relic

If you have any questions, please contact us in the section dGood luck debugging your WordPress site. We hope that you can reduce the issues to ensure a smooth experience for visitors.

Deyi is a digital marketing enthusiast, with a background in web design, content creation, copywriting, and SEO. She is part of ‘s SEO & Localization team. In her free time, she likes to develop projects, read a book or watch a good movie.

Loading Facebook Comments ...
Loading Disqus Comments ...