Please note, this is a STATIC archive of website www.htmlgoodies.com from 16 Nov 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
Wednesday, November 16, 2022

5 Simple Techniques to Debug a WordPress Site

WordPress has dominated the Internet as a well-known content management system (CMS), powering more than 30% of total websites today. One of the main reasons that people prefer WordPress is because of its easy-to-use interface and functionalities.

The core developers behind WordPress have also made the debugging or troubleshooting easier for users, the way they’ve done with other features. Just by adding or removing a number of lines of code, users can enable the debugging easily.

If you are a WordPress developer, you certainly know about the basic WordPress debugging techniques to work on theme and plugin errors. However, these things can be difficult for you, if you are not a tech whiz. You will then need help of developers to debug the errors for you.

This article seeks to help you easily debug WordPress without having to talk to any developers. But, before you learn about these techniques, let’s first learn about the most common types of errors that can occur in your WordPress site.

  • Notice: It isn’t an important error, which doesn’t mean that anything is wrong, but tells about the improvements that can be made to the system.
  • Warning: It’s a more important error than Notice, but no script termination is caused because of it.
  • Fatal error: It’s a serious error that tells about things going wrong, and if a script is terminated.

Having said that, following are the top 5 WordPress debugging techniques that come to your rescue.

1. WP_DEBUG

WP_DEBUG, a PHP constant, allows you to trigger the debug mode for the entire WordPress website. By default, the WP-DEBUG is assumed to be false, and is switched to true in wp-config.php file to help WordPress users in development process.

define( 'WP_DEBUG', true );
define( 'WP_DEBUG', false ); 

When you enable the WP_DEBUG, it will show all the PHP errors, notices, as well as warnings on the screen.

You can also see the notices related to deprecated functions used on your site. It will then indicate new functions which should be used rather than the deprecated functions.

One thing you should take care of is not to use WP_DEBUG or other debugging tools on a live website. These tools are usually created for testing and staging installs.

There are two companions of WP_DEBUG, named WP_DEBUG_LOG and WP_DEBUG_DISPLAY.

The WP_DEBUG_LOG aims to manipulate all the errors and save them to debug.log file in the wp-content directory. This allows you to check or review the notices and errors in future whenever you need.

On the other hand, the WP_DEBUG_DISPLAY controls whether to display debug messages in HTMP of pages or not. By default, it is set to true which means that it will display errors and warnings whenever they’re generated. If you set it to false, the errors will get hidden.

2. WordPress debugging plugins

WordPress allows you to install any plugin on your site as per the functionality needed. Same goes for debugging as well. There are plenty of WordPress debugging plugins out there which you can use for your site. We have curated some of the best

WordPress plugins available for you.

  • Query Monitor — It is an ideal option for you as it comes with advanced features like debugging of REST API requests, redirects, and AJAX calls.
  • Debug Bar — It is another handy plugin that you can use to view valuable information about every webpage of your site. Using it, you can review analysis of queries, templates, PHP installation, as well as other important information.
  • Log Deprecated Notices — This plugin can be used to log the usage of deprecated files, functions, and function arguments.

It is recommended that you use these plugins right after building your website.

3. Server Error Logs

Sometimes, both the WordPress and PHP can’t find some of the errors. For instance, if your website script goes beyond the maximum run time, there will be no PHP error. But, your system might show an ‘Internal Server Error.’ It can be because of an error that caused it at the server, which might be a result of your previous debugging.

In such cases, you will need to check the error log to find whether or not your PHP code or any part of WordPress installation caused any unique error.

When you set up your blog, consult your web host provider or check web hosting settings and know the location in which logging is stored. Usually, it can be found under the logs folder.

4. Firebug

It is a debugging add-on that helps you in analyzing the website to find errors, network problems, design flaws, and interaction of functions.

Known for its logging functionality, Firebug allows you to log all the errors at a single place, and then analyze them easily. You can choose to fix errors whenever it is required.

Firebug is a dedicated add-on for Mozilla Firefox browser, but you can choose its lite version on other browsers as well.

One thing you need to take care of is to disable the browser cache while working with Firebug. This is because, sometimes the cache can interrupt the work or cause delays. For example, if you work on JavaScript code, you should know that it is either not updating or taking more time to update and displaying errors.

5. Doing_it_wrong()

Sometimes when you use the wrong code or make slight mistakes in WordPress coding, then a message like this might be shown:

"Please see Debugging in WordPress for more information. (This message was added in version 3.3.0.)" 

To automatically trigger such errors, you can use the doing_it_wrong() function. This function also suggests you read the page that consists of errors. Such errors can also occur if you don’t call or load scripts in a right manner. To avoid that, you should use an action hook for loading scripts at the right time.

Wrapping Up

These are some of the best techniques that you should consider while debugging your WordPress site. It is recommended that you use Debug Bar for internal debugging analysis. WP_DEBUG has always worked for WordPress sites to know and list the errors. This can help you in understanding the things going wrong with the site.

About the Author

Catherrine Garcia is an experienced Web Developer at WPCodingDev and a passionate blogger. She loves to share her knowledge through her articles on web development and WordPress.

Popular Articles

Featured