Wordpress

Debug WordPress – Tracing the Root cause of Error

WordPress can be a headache for your if it’s not properly working and specially in the case when it outputs some kind of php error, or else gives you just a blank page. Then to debug wordpress, it’s impossible for a newbies who has no experience with wordpress. This post aims to help you find out that what’s actually causing the error in you wordpress blog plus will help you to debug wordpress in no time. After learning this you will be able to trace the error and will able to trace the file which is causing the problem in your wordpress installation.

Debug WordPress

Debug WordPress and trace the error causing File:

Below are some of the ways using which you will be able to trace the error, plus will be able to find out the file which is actually the reason of the error in wordpress.

1- Reading the Error_log of WordPress to Debug WordPress:

Errors are logged automatically in the new wordpress versions. If you are facing an error in the wordpress then In the root folder of your wordpress installation there is created a file named as “error_log“. You should download that file using a ftp client like “Filezilla“. Open this downloaded file and review it for errors. There will be all the errors logged into the file. So, you got the errors now, let’s move on to other way to get the errors in wordpress; in the end I’ll tell you that how can you understand these error lines in wordpress.

Enabling error_log in WordPress if the error_log file is not generated in WordPress root directory:

Suppose, if the error_log file is not created in the wordpress then you can force wordpress to generate the error file. You need to edit the “wp-config.php” file of your wordpress. Add the following lines of code in you wordpress configuration file i-e “wp-config.php

@ini_set('log_errors', 1);
@ini_set('display_errors', 0); /* enable or disable public display of errors in wp (use 'On' or 'Off') */
@ini_set('error_log', dirname(__FILE__) . '/wp-content/logs/php-errors.log'); /* relative path to server-writable log file */
@ini_set( 'error_reporting', E_ALL ^ E_NOTICE ); /* the php parser to  all errors  */

The above code, will let you log the errors to the following path: wp-content/log/php-errors.log; Don’t forget to create a directory in the wp-content named as “log” which must be writeable by the owner too. So, change the permissions of that directory through the ftp client. And allow the owner to write the directory. Re-load the error causing page in your wordpress and then open the directory log, there open up the error logging file named as “php-errors.log” , you will get all the errors there in the file.

Thus, in this way you have successfully enabled the logging system of wordpress errors.

2- View WordPress Errors in the Browser to debug:

I don’t recommend this way, if you are debugging wordpress publicly. If you want to use this way or also the above, be sure that you are in the developing environment where no one can see the error. To view the errors in the browser, you need to edit the “wp-config.php” file again in the root of your wordpress installation using a ftp client.

  1. Open “wp-config.php” and locate this piece of code into it: define(‘WP_DEBUG’, false);
  2. After you have located it, you need to replace false with the true. Now, save the file.
  3. After saving the file, reload the page where there is an error or the page which gives a blank output. Now, you can easily see the errors in the top of the browser page. Thus, again we got the errors.

Understanding the WordPress Error:

You can now easily get errors in the wordpress, whether you are a newbie or else you are a pro. Understanding the error is the part of discussion now. Suppose, your error is like this below:

[22-Jul-2013 16:52:13 UTC] PHP Parse error:  syntax error, unexpected 'endif' (T_ENDIF) in \htdocs\wordpress\wp-content\themes\talkofweb\index.php on line 32

The above error log, shows the time when the error actually occurred. Plus, it also shows that there is a php parse error, means if we do some Google about this error; we may come to know that there is an error in our php markup. Plus, the error indicates that the error causing code is on line 32 of the file index.php placed in “talkofweb” theme folder..

Thus, I edited the file index.php and went to the line 32. There I saw that I forgot to use conditional tag if() correctly. Thus, I corrected the markup, used the if condition correctly and thus the closing of if condition there, known as endif, became just fine. Thus, you can just find out an error and can debug wordpress with quite an ease.

Note: Don’t use all the above method in front of the public, error_logs and the error shown in the browser window, must not be visible to the public. So, always be sure to do all this in a secure environment. Because a potentially critical error if known can be used to exploit your site. You can download the wordpress theme to your computer and can test that using xampp if the error is in theme files.