Error logs can help you to diagnose issues affecting your site. This is achieved by configuring the wp-config file of your WordPress site.
The wp-config.php file is a WordPress configuration file that contains important 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.
But, it also works as a handy debugging tool, which allows you to find and debug errors.
In this tutorial, I’m going to cover the basics of setting up error logs in WordPress and what they mean.
Why do you need error logs?
Finding the root cause of errors in WordPress can sometimes be frustrating and time consuming.
Setting up error logs will help you find those issues quickly, and point you to the root cause of the errors.
Whether you fix the errors yourself or ask a professional, the error logs are an important piece of the puzzle.
Error logs are also useful in keeping track of bugs that might enter your system through plugin updates or bad code.
How error logs can help us diagnose issues
Depending on the type of error, a simple Google search can help you find a solution.
Each line that’s visible in the error log describes the error and displays the file URL which triggered the error.
However, it also uses PHP terminology. Here is how one line of the error log could look like,
PHP Fatal error: Call to undefined function verb_lite_entry_categories() in /home/ivgserve/public_html/simplex/wp-content/themes/simplex-lite/loop-templates/content-featured.php on line 23
For beginners who aren’t familiar with PHP code, this can be daunting. Don’t worry, further on in this tutorial I’ll explain how to use error logs to debug issues.
How to setup error logs in wp-config
Until you’ve enabled debug mode, WordPress won’t create or store your error logs. So, you have to enable the built-in debugging feature yourself.
Here’s how you do it.
Enabling the WordPress debug mode
To enable the debug mode, you need to edit the wp-config.php file.
Start by either logging into your hosting provider’s cPanel or access the site via FTP.
Go to your cPanel File Manager or public_html in your FTP and locate wp-config.php.
Open the file to edit it and find the line that says “That’s all, stop editing! Happy blogging.”
Right before this line, insert the following code.
define( 'WP_DEBUG', true ); define( 'WP_DEBUG_LOG', true ); define( 'WP_DEBUG_DISPLAY', false );
The save your changes.
The WP_DEBUG line activates the WordPress debug mode. However, it only displays the errors and doesn’t store them in the log file. You’ll see the errors and warnings in your dashboard and on the front-end of your site.
It’s possible this line of code is already present in your wp-config file and will be set to false. In that case, simply change it to true.
The WP_DEBUG_LOG line is what stores the errors in the log.
Finally, the WP_DEBUG_DISPLAY line should be used in conjunction with the other definitions. This one controls whether or not the debug messages are inside the pages’ HTML or not.
Note: If any of the above lines of code are already in the wp-config file, replace them with the code mentioned previously.
Once you reload your site, it will generate an error_log file which will be located in your WordPress root directory.
Reviewing the error logs
In order for you to be able to review the logs, you’ll need to trigger them so the system can log them in the error_logs file. You can do this by visiting the pages which where triggering errors. Each page you visit will trigger the errors and the system to record them in the error_logs file.
Then, open the error_logs file and review the logs. It will look something like this,
[21-Oct-2016 16:49:38 UTC] PHP Fatal error: Call to undefined function verb_lite_entry_categories() in /home/ivgserve/public_html/simplex/wp-content/themes/simplex-lite/loop-templates/content-featured.php on line 23 [21-Oct-2016 16:50:51 UTC] PHP Fatal error: Call to undefined function verb_lite_entry_categories() in /home/ivgserve/public_html/simplex/wp-content/themes/simplex-lite/loop-templates/content-featured.php on line 21 [21-Oct-2016 16:54:41 UTC] PHP Fatal error: Call to undefined function verb_lite_entry_categories() in /home/ivgserve/public_html/simplex/wp-content/themes/simplex-lite/loop-templates/content-featured.php on line 22
Error logs usually have the following structure,
- Date
- Error type
- Error description
- File path & line number
This will point you to the files and specific lines of code which are triggering errors.
You can then go line-by-line and find solutions to each error.
This tutorial doesn’t cover how to solve individual WordPress errors, just how to set up the error logs.
But there is a quick & simple way to find solutions for errors.
Use Google to find solutions
Copy and paste each line of the error log into Google but remove any code specific to your site.
Take this line for example,
[21-Oct-2016 16:49:38 UTC] PHP Fatal error: Call to undefined function verb_lite_entry_categories() in /home/ivgserve/public_html/simplex/wp-content/themes/simplex-lite/loop-templates/content-featured.php on line 23
Remove the date and URL specific to your site but include the file name.
PHP Fatal error: Call to undefined function verb_lite_entry_categories() content-featured.php on line 23
Then enter this in a Google search.
You’ll most likely find results for WordPress Support forums or Stack Overflow from users who’ve had similar issues.
If you search through the results, or directly in the WordPress & Stack Overflow forums, you’ll most likely find a solution.
I hope you found this useful, if you have any comments or questions, use the comment form below.