WordPress开发技巧:如何开启调试模式

前端之家收集整理的这篇文章主要介绍了WordPress开发技巧:如何开启调试模式前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我们在使用wordpress开发网站的时候,很多时候会出现一些莫名其妙的问题,但是页面中并没有显示出来错误信息,这时候的我们总是一头雾水,不知道自己该朝哪个方向努力。这篇WordPress教程里,我们就向大家介绍一下开启wordpress调试模式的方法

打开网站根目录,找到wp-config.php文件,将原来的 WP_Debug 设置修改如下:

Crayon-5c891d12dfb8c753924540" class="Crayon-Syntax Crayon-theme-classic Crayon-font-monaco Crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouSEOver" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
Crayon-toolbar" data-settings=" mouSEOver overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">Crayon-title">wp-config.php
Crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
Crayon-button Crayon-nums-button" title="Toggle Line Numbers">
Crayon-button-icon">
Crayon-button Crayon-plain-button" title="Toggle Plain Code">
Crayon-button-icon">
Crayon-button Crayon-wrap-button" title="Toggle Line Wrap">
Crayon-button-icon">
Crayon-button Crayon-expand-button" title="Expand Code">
Crayon-button-icon">
Crayon-button Crayon-copy-button" title="Copy">
Crayon-button-icon">
Crayon-button Crayon-popup-button" title="Open Code In New Window">
Crayon-button-icon">
Crayon-language">PHP
Crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
Crayon-plain-wrap">
Crayon-main" style="">Crayon-table">Crayon-row">
Crayon-nums " data-settings="show">
Crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
Crayon-num" data-line="Crayon-5c891d12dfb8c753924540-1">1
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d12dfb8c753924540-2">2
Crayon-code">
Crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
Crayon-line" id="Crayon-5c891d12dfb8c753924540-1">Crayon-e">defineCrayon-sy">(Crayon-s">'WP_DEBUG'Crayon-sy">,Crayon-h"> Crayon-t">trueCrayon-sy">)Crayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d12dfb8c753924540-2">Crayon-e">defineCrayon-sy">(Crayon-s">'WP_DEBUG_DISPLAY'Crayon-sy">,Crayon-h"> Crayon-t">trueCrayon-sy">)Crayon-sy">;

这样我们就可以看到错误的日志log了。但是有些错误是发生在某些后台进程里,比如cron job,没法显示错误log,这是我们就需要把错误log保存到debug文件中。修改上面的代码如下:

Crayon-5c891d12dfb94265384499" class="Crayon-Syntax Crayon-theme-classic Crayon-font-monaco Crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouSEOver" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
Crayon-toolbar" data-settings=" mouSEOver overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">Crayon-title">wp-config.php
Crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
Crayon-button Crayon-nums-button" title="Toggle Line Numbers">
Crayon-button-icon">
Crayon-button Crayon-plain-button" title="Toggle Plain Code">
Crayon-button-icon">
Crayon-button Crayon-wrap-button" title="Toggle Line Wrap">
Crayon-button-icon">
Crayon-button Crayon-expand-button" title="Expand Code">
Crayon-button-icon">
Crayon-button Crayon-copy-button" title="Copy">
Crayon-button-icon">
Crayon-button Crayon-popup-button" title="Open Code In New Window">
Crayon-button-icon">
Crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
Crayon-plain-wrap">
Crayon-main" style="">Crayon-table">Crayon-row">
Crayon-nums " data-settings="show">
Crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
Crayon-num" data-line="Crayon-5c891d12dfb94265384499-1">1
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d12dfb94265384499-2">2
Crayon-num" data-line="Crayon-5c891d12dfb94265384499-3">3
Crayon-code">
Crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
Crayon-line" id="Crayon-5c891d12dfb94265384499-1">Crayon-e">defineCrayon-sy">(Crayon-s">'WP_DEBUG'Crayon-sy">,Crayon-h"> Crayon-t">trueCrayon-sy">)Crayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d12dfb94265384499-2">Crayon-e">defineCrayon-sy">(Crayon-s">'WP_DEBUG_DISPLAY'Crayon-sy">,Crayon-h"> Crayon-t">falseCrayon-sy">)Crayon-sy">;
Crayon-line" id="Crayon-5c891d12dfb94265384499-3">Crayon-e">defineCrayon-sy">(Crayon-s">'WP_DEBUG_LOG'Crayon-sy">,Crayon-h"> Crayon-t">trueCrayon-sy">)Crayon-sy">;

修改完成以后,我们可以在 wp-content文件夹下的 debug.log 文件中看到相应的错误信息。

切记网站调成成功以后,需要把调试模式关闭,否者一旦有错误,访问者也将看到网站的系统错误。还有就是wp-content文件夹下的debug.log会变得很大,把服务器的空间都用完。关闭的方式如下:

Crayon-5c891d12dfb96804750896" class="Crayon-Syntax Crayon-theme-classic Crayon-font-monaco Crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouSEOver" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
Crayon-toolbar" data-settings=" mouSEOver overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">Crayon-title">wp-config.php
Crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
Crayon-button Crayon-nums-button" title="Toggle Line Numbers">
Crayon-button-icon">
Crayon-button Crayon-plain-button" title="Toggle Plain Code">
Crayon-button-icon">
Crayon-button Crayon-wrap-button" title="Toggle Line Wrap">
Crayon-button-icon">
Crayon-button Crayon-expand-button" title="Expand Code">
Crayon-button-icon">
Crayon-button Crayon-copy-button" title="Copy">
Crayon-button-icon">
Crayon-button Crayon-popup-button" title="Open Code In New Window">
Crayon-button-icon">
Crayon-language">PHP
Crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
Crayon-plain-wrap">
Crayon-main" style="">Crayon-table">Crayon-row">
Crayon-nums " data-settings="show">
Crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
Crayon-num" data-line="Crayon-5c891d12dfb96804750896-1">1
Crayon-code">
Crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
Crayon-line" id="Crayon-5c891d12dfb96804750896-1">Crayon-e">defineCrayon-sy">(Crayon-s">'WP_DEBUG'Crayon-sy">,Crayon-h"> Crayon-t">falseCrayon-sy">)Crayon-sy">;

原文链接:https://www.f2er.com/wordpress/238449.html

猜你在找的wordpress相关文章