April 16, 2020
3 least Read
Turn on WP_Debug on the page WordPress can help you better understand what happens on the website. Especially useful when something goes wrong. WordPress Debug is essential for theme and plugin developers if they want to publish the product publicly on WordPress.
Therefore, in this article, we will show you everything you need to know about WP_DEBUG and how to use it.
Why is WordPress Debug important?
WordPress Debug or WP_DEBUG is a PHP constant that enables debug mode in WordPress. You can find it in the file wp-config.php. Although this mode is off by default, you can turn it on when needed. So what are the reasons why WordPress Debug is important:
- Firstly, this mode provides information about the problem. By saving the log file, it will record all activities that occur on the site and thus can correct the problem.
- Second, WordPress Debug (WP_DEBUG) will display a list of outdated functions in the WordPress theme or in the plugin. These are functions that are marked as inactive in the future. This message tells you which option is used instead.
- Another important reason is that when you want to build a theme or plugin you need to turn on WP_Debug. WordPress Codex It is recommended that all developers use WP_DEBUG when creating products. So when there are problems or warnings, other developers can check and fix the code.
- If it is not compatible with WP_DEBUG, the official WordPress library will not endorse your plugin or theme.
Practical use of WordPress Debug
Now that you have an overview of WP_DEBUG, we will cover the practical use.
WP_DEBUG is in the file wp-config.php and by default, this value is set to "False". If you want to enable it, you must change it to "True". To do so, you will need an FTP client, like FileZilla or file manager to access the file.
In the example, we will use File Manager Hostinger.
- Search for the file wp-config.php in the root directory of the site. In our example, it is in hostinger-dev-9.xyz/public_html/wp-config.php.
- Open the file and find
define( 'WP_DEBUG', false )
- After determining the location, change false Fort true. Then save the file.
If there is no such code in the file wp-config.phpYou can add above it lines / * That’s all, stop editing! Happy blogging. * /.
Remember that debugging should not be enabled in a running site as this mode is designed for development purposes.
By enabling WP_DEBUG_LOG, users can save all errors in the file debug.log. This function works in tandem with WP_DEBUG and can help reproduce the problem to fix the problem.
To enable it, open the file wp-config.php and enter the following line define (‘WP_DEBUG’, true);
After you activate the function, the file debug.log will be automatically saved in the directory / wp-content / Web's. You can directly view the file in your browser.
You should disable WP_DEBUG_DISPLAY so that the WordPress Debug error message is not displayed on the site.
By default, whenever an error occurs, it will be generated and displayed within the HTML code. And unlike WP_DEBUG, the initial value is "true"And you have to change it to"false”To hide all errors.
Or if not available, you need to insert this line into the file wp-config.php right below the line define (‘WP_DEBUG’, true);
All of these features: WP_DEBUG, WP_DEBUG_LOG and WP_DEBUG_DISPLAY can be used at the same time to enable debugging, saving log files and hiding all errors.
Understanding how to use WP_DEBUG has many important benefits for WordPress site owners and developers. You can use it to enable debug mode and save or hide all errors for better site development. Moreover, the process is actually quite easy.
Here is a summary of all steps for using WP_DEBUG, WP_DEBUG_LOG and WP_DEBUG_DISPLAY:
- WP_DEBUG - Find the file wp-config.php and establish define (‘WP_DEBUG’, false); Fort true.
- WP_DEBUG_LOG - Add define (‘WP_DEBUG_LOG’, true); below the line define (‘WP_DEBUG’, true);.
- WP_DEBUG_DISPLAY - Add define (‘WP_DEBUG_DISPLAY’, false); below the line define (‘WP_DEBUG’, true);.
If you have any questions about WordPress Debug or WP_DEBUG, leave us a message in the comment section below.