How to enable the debug mode on WordPress

Marc Wag­ner

June 9, 2021

3 min read|

Word­Press has a built-in debug mode that allows you to save errors, war­nings and hints in a sepa­ra­te log file.

How do I activate the debug mode? #

You can acti­va­te the debug mode of Word­Press direct­ly in the wp-config.php. This is loca­ted in the root direc­to­ry of your Word­Press instal­la­ti­on.

image 32
Acti­va­te Word­Press debug mode.
define('WP_DEBUG',true);

Now the debug mode is acti­va­ted, and error mes­sa­ges are stored in the log file.

WP_DEBUG_LOG #

Using WP_DEBUG_LOG, you can spe­ci­fy whe­ther the mes­sa­ges should be stored in the log file or not.

define('WP_DEBUG_LOG', true); // true | false

You can also use the para­me­ter to save your log file to ano­ther loca­ti­on:

define('WP_DEBUG_LOG','tmp/my-custom-error.log');

But for this to work, you need to have the debug mode enab­led via WP_DEBUG.

WP_DEBUG_DISPLAY #

You can also dis­play the error mes­sa­ges in the brow­ser. For this, you use the para­me­ter WP_DEBUG_DISPLAY.

define('WP_DEBUG_DISPLAY', true); // true | false

War­ning: If you use WP_DEBUG_DISPLAY, visi­tors of your site can of cour­se also see the error mes­sa­ges.

Note: If you are using a cache like WP Rocket, aut­op­ti­mi­ze or simi­lar, you may need to clear it first to see the error mes­sa­ges.

WP_DEBUG_DISPLAY enables (true) or dis­ables (fal­se) the out­put of error mes­sa­ges direct­ly in the brow­ser.

Where can I find the log file on WordPress? #

You can find the log file of Word­Press under:

wp-content/debug.log


Howe­ver, it is also pos­si­ble that the loca­ti­on has been chan­ged. For this, you can look in the wp-config.php.

Check whe­ther an ent­ry WP_DEBUG_LOG was stored. The new path should also be stored the­re.

How can I change the location for the log file? #

You can chan­ge the loca­ti­on for the log file at any time in the wp-config.php. The wp-config.php is loca­ted in the root direc­to­ry of your Word­Press instal­la­ti­on.

Add the fol­lo­wing the­re (if this ent­ry does not alre­a­dy exist):

define('WP_DEBUG_LOG','/tmp/my-custom-log.log');

With this, the new log file should be used from now on.

Note: For this to work, you must of cour­se enable debug mode.

How to analyze the WordPress log file #

If an error occur­red on your side, and you check the log file, you pro­ba­b­ly won’t under­stand any­thing at first.

First, very important­ly, find out when the error occur­red. All ent­ries are pro­vi­ded with a timestamp. So you can alre­a­dy exclude a lot of ent­ries.

Next, we still need to distin­gu­ish bet­ween:

  • PHP War­ning
  • PHP Noti­ce
  • PHP Error / PHP Fatal Error / PHP Par­se error

To find the error, we can igno­re all PHP War­ning and PHP Noti­ce. The most inte­res­t­ing are the error mes­sa­ges.

If you have found an error that matches the timestamp of the pro­blem, we have alre­a­dy found the cau­se.

But what now? Tog­e­ther with the error, you will also find the file that cau­sed the error in the log file. This can look like this, for exam­p­le:

image 34

Both at the begin­ning of the error mes­sa­ge and at the end, it says whe­re this error mes­sa­ge was thrown (Thrown). In our exam­p­le, the file Shortcode.class.php in the plug­in f12-con­­tent-pro­­tec­­ti­on cau­ses the error.

Now you can cont­act the plug­in aut­hor, disable the plug­in by sim­ply ren­aming the fol­der, or fix the error yours­elf.

No mat­ter what you do, be sure to back up your web­site and data­ba­se.

88e86fcb816eff22bc917094df2862d8dd5c0e978b333e6dd5f36f808990c261 96

Arti­kel von:

Marc Wag­ner

Hi Marc here. I’m the foun­der of Forge12 Inter­ac­ti­ve and have been pas­sio­na­te about buil­ding web­sites, online stores, appli­ca­ti­ons and SaaS solu­ti­ons for busi­nesses for over 20 years. Befo­re foun­ding the com­pa­ny, I alre­a­dy work­ed in publicly lis­ted com­pa­nies and acqui­red all kinds of know­ledge. Now I want to pass this know­ledge on to my cus­to­mers.

Hast du eine Fra­ge? Hin­ter­lass bit­te einen Kom­men­tar