18 March, 2023
What Is WordPress Debug? How to Debug in WordPress

A website administrator faces many problems and has many jobs to handle. Running into errors is hard to avoid. They affect how the website works, and in the worst case the site may become unreachable. This is when WordPress Debug becomes an important skill, and every administrator needs the right knowledge to do it. With it, a slow website or a plugin error can be fixed quickly and simply.
What is Debug?
Debug, or debugging, is the work of identifying and removing bugs or errors in code when needed. It is also the final stage of the process, where you verify that the code is correct and precise and that no unexpected problems can occur. Programmers do this with dedicated debugging tools. This step is indispensable when developing software, applications or websites for real-world use.
Typical debugging strategies include unit tests, code previews and finally pair programming. Before code or software is published to users, developers try to find every problem, then isolate and fix it. This helps ensure the final product is of the best quality. See more about The website testing process
Why WordPress Debug matters
WordPress Debug, or WP_DEBUG, is a constant PHP that turns on debug mode with WordPress. You can find it in the file wp-config.php when needed. Although this mode is off by default, turning it on is very useful because:
- This mode provides all information and problems by saving them to a log file. It records everything that happens on the site, so finding and fixing problems becomes much easier and faster.
- WordPress Debug lists deprecated functions in WordPress themes or plugins. It lets us mark which features no longer work, so users can easily choose suitable replacements.
- When we want to build a theme or plugin, we need to turn on WP_Debug because the WordPress Codex always recommends developers use it, so that when errors, problems or warnings appear, checking and fixing the code is done well and fast.
- If it is not compatible with WP_Debug then the WordPress directory will not certify the theme or plugin you are using.
See more about some website errors and how to fix them:
Ways to debug on WordPress
When a WordPress site has a problem, or the white screen of death appears, the common fix is to deactivate the plugin or theme, then check it and turn the update back on. This narrows down the possible causes considerably. In practice, though, it takes a lot of time and sometimes does not work, and we may overlook the real problem. So for WordPress debugging we can use a few approaches such as:
Enable WPDB Error Reporting
To find errors directly related to the database, enabling WPDB error reporting is always recommended. The global $wpdb object has a variable named $show_errors, and when we set it to true, WordPress shows SQL errors on screen right away.
To turn on this feature, follow the path /public_html/wp-includes/wp-db.php and open the file. Then search for wpdb class and change the variable $show_errors to True.
Check the error logs on the website
In some cases the website shows a server error when browsing. For problems like this, checking the website's error logs is a must. Checking the general log also helps new users and programmers quickly find the actual problem on the site.
After checking, we use Google to search for information and work out how to handle the error we found. This gets the WordPress site back to normal use quickly and effectively.
Use a WordPress staging environment when editing code
To reduce bugs on a WordPress website, deploy the code to a staging website first. A staging website is a nearly exact copy of your live website. It is hosted on a separate private subdomain without affecting the live version. It works as a code testing platform, and once changes are complete we can push them to the main site.
This environment is not visible to visitors or search engines. So we are free to adjust, change, improve or test any change we want, without any negative impact on the live website, while still editing quickly and effectively as needed.
Detect PHP errors
To catch PHP errors in your scripts as early as possible, phpinfo is the first choice. With this file we can easily output the current state of PHP when needed. It includes options such as compilation, version, environment, HTTP headers, extensions, OS version and license.
To do this, we need to open the php.ini configuration file and turn on error reporting. However, some Web Hosting today disable this option. This happens because we do not have root access to enable the feature as needed.
In that case we should consider using a PHP code checker instead. It simply helps review errors in the code and also evaluates it more thoroughly and in more detail. We can also use popular IDEs such as Eclipse or PHPStorm.
Enable SCRIPT_DEBUG
By default WordPress uses minified versions of the CSS as well as JavaScript files, mainly to improve a website's page load time. But this can be a problem, because it can hide errors inside the scripts or plugins in use.
To change how scripts run on the website, WordPress provides a constant that we can add to the file wp-config.php with the syntax:
define( ‘SCRIPT_DEBUG’, true );
when the value is set to true, WordPress automatically loads the non-minified versions of all CSS and JavaScript files, and plugins will use the full versions.
A few debugging tools
If you simply want to track errors on a WordPress site, using WordPress debugging plugins is the recommended way. They support the needs of both administrators and programmers well. Notable ones include:
Query Monitor
This plugin provides a developer tool panel right inside WordPress, where you can easily inspect database queries, PHP errors, HTTP API calls, hooks and actions, and more as needed.
New Relic
A more powerful premium WordPress debugging tool to consider is New Relic. It monitors user experience, maps the WordPress architecture, analyzes and improves website performance, and detects abnormal errors before they appear. Its features let us collect data and gather the full information needed to fix problems in time, so visitors get the best experience on the website.
There is a lot to know about WordPress debug that programmers and website administrators cannot skip. With the necessary knowledge, an understanding of why it matters and the common ways to debug in WordPress, you will have a useful foundation to apply whenever needed. Building a high-quality website that runs stably and gives customers the best experience then becomes much easier.
Learn more about WordPress:
- What is Jetpack? What to know about the Jetpack WordPress plugin
- What is a taxonomy? How to use custom WordPress taxonomies effectively
- WordPress website security methods and plugins
- What is WordPress Hosting and how to choose the right WordPress hosting service
Related articles
Professional website
design services
Own a website with a beautiful, 100% exclusive design and a lifetime warranty, with the ability
to expand features flexibly as your business grows, starting today!































Free AI courses
AI tools at work
VI
EN
