{"id":123083,"date":"2017-07-01T13:00:00","date_gmt":"2017-07-01T13:00:00","guid":{"rendered":"http:\/\/wpmu.org\/?p=123083"},"modified":"2022-03-15T22:49:36","modified_gmt":"2022-03-15T22:49:36","slug":"debugging-wordpress-how-to-use-wp_debug","status":"publish","type":"post","link":"https:\/\/wpmudev.com\/blog\/debugging-wordpress-how-to-use-wp_debug\/","title":{"rendered":"Debugging WordPress: How to Use WP_DEBUG"},"content":{"rendered":"<p>Every good developer should turn on debugging before getting started on a new plugin or theme. In fact, the WordPress Codex &#8220;<a href=\"https:\/\/wordpress.org\/support\/article\/debugging-in-wordpress\/\" target=\"_blank\">highly recommends<\/a>&#8221; that developers use <code>WP_DEBUG<\/code> mode while working on code they plan to release publicly.<\/p>\n<p>Unfortunately, many developers don&#8217;t follow this advice simply because they forget about the debugging tools built-in to WordPress or just don&#8217;t know how to use them.<\/p>\n<p>In this post, I&#8217;ll go through the basic debugging tools available and show you how easy they are to use.<\/p>\n<ul>\n<li><a href=\"#WP_DEBUG\">Debugging With WP_DEBUG<\/a><\/li>\n<li><a href=\"#WP_DEBUG_LOG\">Logging Errors With WP_DEBUG_LOG<\/a>\n<ul>\n<li><a href=\"#debug-log\">Accessing the debug.log File<\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"#WP_DEBUG_DISPLAY\">Turn Off Displaying Errors On Your Site With WP_DEBUG_DISPLAY<\/a><\/li>\n<li><a href=\"#all\">Putting it All Together<\/a><\/li>\n<\/ul>\n<h2 id=\"WP_DEBUG\">Debugging With WP_DEBUG<\/h2>\n<p>The most important debugging tool you need to know about is <em>WP_DEBUG<\/em>.<\/p>\n<p><em>WP_DEBUG<\/em> is a boolean constant, which triggers the &#8220;debug&#8221; mode throughout WordPress. It&#8217;s found in the <em>wp-config.php<\/em> file in your WordPress install.<\/p>\n<p>When set to &#8220;true,&#8221; you\u2019ll start seeing PHP notices \u2013 not so much errors as they are helpful messages for developers \u2013 and WordPress-generated debug messages, particularly deprecated function usage, displayed on your site&#8217;s pages.<\/p>\n<p>Deprecated functions, which are contained in many WordPress releases, are functions that have been flagged to die at a later date. It&#8217;s important to know if you are using a deprecated function in a theme or plugin you&#8217;re working on so you can find a replacement to use instead.<\/p>\n<p>To turn on WP_DEBUG, find the following line of code to your <em>wp-config.php<\/em> file:<\/p>\n<div class=\"gist\" data-gist=\"1b61c6ea012f69190264e22782c66824\" data-gist-file=\"wp-config.php\"><a class=\"loading\" href=\"https:\/\/gist.github.com\/1b61c6ea012f69190264e22782c66824.js?file=wp-config.php\">Loading gist 1b61c6ea012f69190264e22782c66824<\/a><div class=\"gist-consent-notice\" style=\"display:none\"><p>Please <a href=\"javascript:Cookiebot.renew()\">update your cookie preferences<\/a> to enable preference cookies to view this gist.<\/p><\/div><\/div>\n<p>Then, replace <code>false<\/code> with <code>true<\/code> and save the file.<\/p>\n<p>To turn the constant off, just replace &#8220;true&#8221; with &#8220;false&#8221;. <em>WP_DEBUG<\/em> is set to false by default.<\/p>\n<p><em>WP_DEBUG<\/em> provides a handy way to troubleshoot problems when something goes wrong with your site.<\/p>\n<p>It&#8217;s important to keep in mind that\u00a0<em>WP_DEBUG<\/em> <strong>should not be used on a live site<\/strong>. While it&#8217;s a useful feature during development, it can be dangerous on a live site because text in the PHP notices can reveal details about your code, paths and other information to visitors to your site.<\/p>\n<h2 id=\"WP_DEBUG_LOG\">Logging Errors With WP_DEBUG_LOG<\/h2>\n<p>Another handy tool is <code>WP_DEBUG_LOG<\/code>, which can be used in conjunction with <code>WP_DEBUG<\/code> to save all error messages to a <em>debug.log<\/em> file.<\/p>\n<p>This is an especially useful feature if you want to review notices later.<\/p>\n<p>To turn on debug logging, simply add the following line of code to your <em>wp-config.php<\/em> file:<\/p>\n<div class=\"gist\" data-gist=\"714a617e37d1a7936393fd51cf58e8be\" data-gist-file=\"wp-config.php\"><a class=\"loading\" href=\"https:\/\/gist.github.com\/714a617e37d1a7936393fd51cf58e8be.js?file=wp-config.php\">Loading gist 714a617e37d1a7936393fd51cf58e8be<\/a><div class=\"gist-consent-notice\" style=\"display:none\"><p>Please <a href=\"javascript:Cookiebot.renew()\">update your cookie preferences<\/a> to enable preference cookies to view this gist.<\/p><\/div><\/div>\n<h3 id=\"debug-log\">Accessing the <em>debug.log<\/em> File<\/h3>\n<p>Once you have added the line above, you can find the <em>debug.log<\/em> error log located in the <em>\/wp-content\/<\/em> directory of your site. You can access this directory through <a href=\"https:\/\/wpmudev.com\/blog\/what-is-ssh-wordpress\/\" target=\"_blank\">SSH<\/a>, <a href=\"https:\/\/wpmudev.com\/blog\/ftp-wordpress\/\" target=\"_blank\">FTP<\/a> or the <strong>File Manager<\/strong> in cPanel.<\/p>\n<p>After logging into cPanel, go to <strong>Files &gt; File Manager<\/strong>.<\/p>\n<div  class=\"wpdui-pic-regular  \">\n<figure class=\"wp-caption alignnone\" data-caption=\"true\"><img loading=\"lazy\" decoding=\"async\" class=\"attachment-600x600 size-600x600\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2017\/06\/cpanel-file-manager.png\" alt=\"cPanel homepage after logging in\" width=\"600\" height=\"300\" \/><figcaption class=\"wp-caption-text\">Click on <strong>File Manager<\/strong> after logging into cPanel.<\/figcaption><\/figure>\n<\/div>\n<p>Navigate to the root of your site and click on the <em>\/wp-content\/<\/em> folder. If errors occurred, you should see <em>debug.log<\/em> listed. Click on it, then on the <strong>View<\/strong> or <strong>Download<\/strong> buttons in the menu toward the top.<\/p>\n<div class=\"wpdui-pic-full \" style=\"background-image: url(https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2017\/06\/cpanel-debug-log.png); background-size: cover; background-position: center center; min-height: 270px;\">\n<figure class=\"wp-caption alignnone\" data-caption=\"true\"><img loading=\"lazy\" decoding=\"async\" class=\"attachment-1500x1500 size-1500x1500\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2017\/06\/cpanel-debug-log.png\" alt=\"The wp-content folder in cPanel's File Manager.\" width=\"1500\" height=\"400\" \/><figcaption class=\"wp-caption-text\">Click on <em>debug.log<\/em>, then either the <strong>View<\/strong> or <strong>Download<\/strong> buttons.<\/figcaption><\/figure>\n<\/div>\n<p>If you click <strong>View<\/strong>, you can see the error messages directly in your browser. You can download the file instead if you need to pass it along to a plugin or theme author or <a href=\"https:\/\/wpmudev.com\/support\/\" target=\"_blank\">our free expert 24\/7 support team<\/a>.<\/p>\n<h2 id=\"WP_DEBUG_DISPLAY\">Turn Off Displaying Errors On Your Site With WP_DEBUG_DISPLAY<\/h2>\n<p>If you don&#8217;t want error messages published to your site&#8217;s pages you should use <em>WP_DEBUG_DISPLAY<\/em>.<\/p>\n<p>This is another useful constant, which allows you to control whether debug messages are shown inside the HTML of your site.<\/p>\n<p>The default is &#8220;true,&#8221; which shows errors and warnings as they are generated. Changing this to &#8220;false&#8221; will hide all errors.<\/p>\n<p>This constant should be used in conjunction with <em>WP_DEBUG_LOG<\/em>.<\/p>\n<p>To use his feature, just add the following line of code to your <em>wp-config.php<\/em> file:<\/p>\n<div class=\"gist\" data-gist=\"ca892f6002869fccbbde6023e86d34b0\" data-gist-file=\"wp-config.php\"><a class=\"loading\" href=\"https:\/\/gist.github.com\/ca892f6002869fccbbde6023e86d34b0.js?file=wp-config.php\">Loading gist ca892f6002869fccbbde6023e86d34b0<\/a><div class=\"gist-consent-notice\" style=\"display:none\"><p>Please <a href=\"javascript:Cookiebot.renew()\">update your cookie preferences<\/a> to enable preference cookies to view this gist.<\/p><\/div><\/div>\n<h2 id=\"all\">Putting it All Together<\/h2>\n<p>It&#8217;s easy to use all three constants together if you want to turn debugging on and log error messages but hide notices displayed on your site:<\/p>\n<div class=\"gist\" data-gist=\"75fb311cc2c5d23ffb527ddf3d20557f\" data-gist-file=\"wp-config.php\"><a class=\"loading\" href=\"https:\/\/gist.github.com\/75fb311cc2c5d23ffb527ddf3d20557f.js?file=wp-config.php\">Loading gist 75fb311cc2c5d23ffb527ddf3d20557f<\/a><div class=\"gist-consent-notice\" style=\"display:none\"><p>Please <a href=\"javascript:Cookiebot.renew()\">update your cookie preferences<\/a> to enable preference cookies to view this gist.<\/p><\/div><\/div>\n<p>Don&#8217;t forget that <em>WP_DEBUG<\/em>\u00a0is for local development use and\u00a0<strong>should not<\/strong> be used on live sites.<\/p>\n<p><em><strong>Editor\u2019s Note:<\/strong><\/em><em> This post has been updated for accuracy and relevancy.<br \/>\n[Originally Published: 2013 \/ Revised: March 2022]<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Every good developer should turn on debugging before getting started on a new plugin or theme. In fact, the WordPress Codex &#8220;highly recommends&#8221; that developers use WP_DEBUG mode while working on code they plan to release publicly. Unfortunately, many developers don&#8217;t follow this advice simply because they forget about the debugging tools built-in to WordPress or just don&#8217;t know how to use them. In this post I&#8217;ll go through the basic debugging tools available and show you how easy they are to use.<\/p>\n","protected":false},"author":54213,"featured_media":166044,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"blog_reading_time":"","wds_primary_category":0,"wds_primary_tutorials_categories":0,"footnotes":""},"categories":[263],"tags":[4005],"tutorials_categories":[],"class_list":["post-123083","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-debugging"],"_links":{"self":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/123083","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/users\/54213"}],"replies":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/comments?post=123083"}],"version-history":[{"count":12,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/123083\/revisions"}],"predecessor-version":[{"id":207473,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/123083\/revisions\/207473"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/media\/166044"}],"wp:attachment":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/media?parent=123083"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/categories?post=123083"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/tags?post=123083"},{"taxonomy":"tutorials_categories","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/tutorials_categories?post=123083"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}