WordPress has a debugging mechanism that lets you identify errors and fix them accordingly. It lets you log the errors using the wp-config >file. The wp-config.php file is a WordPress config file that contains important WordPress settings. These settings tell your website how to connect to your WordPress database, which database table prefix to use, and generates authentication keys to make your WordPress site more secure.
It helps to identify and fix common errors in WordPress websites. In this tutorial, you will learn how you can easily set up the debugging mechanism in the WordPress website.
- A Domain Name (example.com)
- cPanel Credentials
- FTP Client (Cyberduck, Filezilla)
- Text Editor (Sublime Text, Notepad)
Login into your cPanel with your username and password. Locate File Manager and Click on it.
Click on public_html on the left side menu and locate the wp-config.php. You can also use an FTP client to connect to your server and download the wp-config.php file.
Right click on wp-config.php and click View/Edit. A pop up window will appear. Click Edit again. Download the file and edit using text editor for FTP clients.
Search for the keyword WP_debug and modify the code as below:
define( 'WP_DEBUG', true );
This snippet tells WordPress to activate the debug mode.
By default, it is set as false. By setting true, now you have enabled the debugging mode of your WordPress site. When you enable the debugging mode, you will see errors and warning on the front end of your website. This is okay if you are testing your website on a staging environment.
For live sites, you can instead log your errors into your wp-config.php file. Add the following line of code after the above wp_debug line.
define( 'WP_DEBUG_LOG', true );
It is possible that this code already exists in your wp-config.php file and is set to false. In that case, you just need to change it to true.
Click Save changes on the top right corner to save your changes.
This above line alone will turn on WordPress debug mode. However the downside of using this debugging alone is that you will see WordPress errors and warnings inside your admin area as well as front page of your website. This will create a bad user experience.
Your WordPress logs are now ready to be viewed if needed. It is located inside the public_html directory of your WordPress site.
Go to your site and visit the pages with errors and access the /public_html/wp-content/ to find the file debug.log
Download the debug.log file to view the logged issues and warnings.
The error log will not track issues that have occurred in the past. Therefore, if you’re trying to troubleshoot a specific issue, you’ll need to trigger it again by interacting with the element or performing the action that caused it. This should prompt WordPress debugger to log the error.
By following these steps, you can easily track your errors and find solutions to them.