WordPress打开Debug模式调试模式

在开发WordPress 主题的时候务必要开启Debug 模式(调试模式),以便检测出隐藏在前端页面背后的bug。下面就为大家简单介绍一下开启的方法。

在WordPress 根目录下的wp-config.php 文件大概75行下有下面一段代码:

/**
 * For developers: WordPress debugging mode.
 *
 * Change this to true to enable the display of notices during development.
 * It is strongly recommended that plugin and theme developers use WP_DEBUG
 * in their development environments.
 */
define('WP_DEBUG', false);

按照其说明,将 false 改成ture 就可以开启调试模式。

调试内容提示在主页上可以看到提示.

高级技巧

wp-settings.php 中打开日志并指定日志文件:

@ini_set('log_errors','On');
@ini_set('display_errors','Off');
@ini_set('error_log','/var/www/html/test.com/logs/error.log');

需要注意可能出现的权限问题,可以创建好目录再执行chmod赋予写权限,让系统能写日志。

应该就OK了,之后出问题页面上会直接打印堆栈信息,并且对应目录下的error.log也会记录。