September 27, 2019
4 min Read
Luqmanul M.
There probably is no such thing as perfect code, and it is every webmaster nightmare whenever bugs occur on their sites or plugins. So today, we’re going to show you tips on how to debug WordPress, helping you to figure out things that may go out of your control.
Debugging, or simply debug, means to identify and remove bugs or errors in your code. The final step of debugging is to test the code correction and make sure that the problem doesn’t happen again.
This is mainly performed by developers using debugging tools, and it’s a part of a routine in the software development stage.
The debugging process can be done using strategies such as unit test, code review, and pair programming.
So before the code or software is published to the users, developers will try to find any issues, then isolate and fix it.
Sometimes, fixing the code can be a real headache, as it might take longer than writing the code itself.
When your WordPress site crashes or has the white screen of death (WSoD), the common response is to deactivate plugins/themes and check for their updates.
While that is helpful for narrowing down the culprit, it can be time-consuming, inefficient, and you could also let the real issue slide unnoticed. That’s why having the right tools can be a real game-changer.
Activating WP-DEBUG is probably the most simple way to log problems on a WordPress site. But unfortunately, some developers don’t do this, most likely because they forget this feature exists.
WP_DEBUG is a constant that triggers the “debug” mode in WordPress, and you can find it in the wp-config.php file. Its log can record all the activities on your site and help troubleshoot any problems.
We’ve covered a more detail instruction about WP_DEBUG in this tutorial.
To detect any problems related to the database, you can enable WPDP error reporting.
The global $wpdb object has a variable called $show_errors. And if you set this to true, you can make WordPress to output the SQL errors to the screen for any given query.
To enable this, go to your /public_html/wp-includes/wp-db.php and open the file. Search for the wpdb class and change the $show_errors variable to true.
Sometimes, you can encounter the interval server errors page when browsing your site. And to fix such an issue, you can review your website error logs.
Doing a general log check-up can help both beginners and advanced developers to detect the website’s problem.
You can then use Google search to look for a possible fix. We’ve covered more detailed steps to check website error log in this tutorial.
If you want to minimize bugs on your WordPress site, you can do so by implementing the code first on a staging site.
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 whatever codes you want to push for your live site.
This environment is mostly not visible to visitors and search engines. So you can have more freedom to tweak, tune, and test the changes you want to bring, without affecting your public, live site.
By default, WordPress uses the minified version of CSS and JavaScript files to help improve your site’s load time. However, this can be a problem because it may hide errors in the scripts/plugins that you use.
To change the script execution, WordPress also provides a constant that we can add to the wp-config.php file, that is:
define( 'SCRIPT_DEBUG', true );
When the value defined as true, WordPress will automatically load the non-minified versions of all CSS and JavaScript files, making all plugins use their full version.
You can detect the PHP errors early in your scripts using phpinfo. This file can output information about the current state of PHP, including the compilation options and extensions, version, environment, OS version, HTTP headers, and license.
To do so, you can configure the php.ini file to enable error reporting. However, some hosting services, including Hostinger’s shared hosting plan, disable this option.
That’s because you don’t have the root access to enable the feature.
But, you can use PHP code checker instead, which provides you with a straightforward assistant to review botches in your code. And for a more thorough review, you can also use IDEs like Eclipse or PHPStorm.
If you need simplicity to monitoring bug on your WordPress site, you can also take advantage of WordPress debugging plugins.
This plugin provides a developer tool panel on WordPress. You can enable database queries, PHP errors, HTTP API calls, hooks & actions, stop editor blocks, enqueued scripts & stylesheets, and more.
Alternatively, you can also use Debug Bar and Simply Show Hooks to help you debug WordPress site. However, these two plugins may have compatibility issues with the most recent version of WordPress.
You can also perform a more robust debug using a premium tool such as New Relic. This app will help you to monitor the user experience, map your WordPress architecture, analyze and improve the site’s performance, and detect anomalies before they happen.
All of those features will help you to gather data for troubleshooting so you can provide the best possible visitors’ experience. You can trial New Relic for 14-day free.
That’s all the tips you need to know about debugging WordPress site. As a developer, you need to identify and fix the problems before pushing whatever code/plugins to users. As a webmaster, you can also use debugging tools to identify what causes performance issues on your website.
To debug your WordPress site, you can do the following:
Good luck for debugging your WordPress site, we hope that you can mitigate problems to ensure a seamless visitor’s experience.
LEAVE A REPLY