PHP Debugging in WordPress Websites

by | Nov 12, 2021 | Technical Help, Web Hosting

One of the harder parts of error hunting in a WordPress site can be debugging the PHP code.

Fortunately, WordPress comes with specific debug systems that can simplify the process. The debug systems also standardize code across the core, plugins and themes.

I’ll describe describe some debugging tools in WordPress and how to implement them in your WordPress website. This will enable your awareness of errors.

If you are not a programmer, you can still benefit. These settings can be used to show detailed information about errors. Making your web hoster aware of the errors can help to reduce the costs involved with getting fixes implemented for them.

An Example of wp-config.php Code for Debugging

CharlesWorks PHP error code articleThe wp-config.php file is the main configuration settings file for your WordPress website. Be very careful when editing it. I always suggest saving the original before editing – just in case. In this configuration file are important settings that allow the site to communicate with its database as well as other extremely important functions.

By inserting the following code in your wp-config.php file, you will be able to log all errors, notices, and warnings to a file called debug.log. In the code example here, that file will be placed in the wp-content directory. Most importantly, it will hide the errors so they do not interrupt page generation. Therefore, a sit can be live while you are debugging some of its functionality behind the scenes.

Be careful to place the debugging code before this line in your wp-config.php file:

/* That's all, stop editing! Happy blogging. */

Here is the code:

// This puts us in the WP_DEBUG mode:
define( 'WP_DEBUG', true );

// This enables the debug logging directly to the /wp-content/debug.log file:
define( 'WP_DEBUG_LOG', true );

// This disables the display of errors and warnings:
define( 'WP_DEBUG_DISPLAY', false );
@ini_set( 'display_errors', 0 );

// This lets us use dev versions of core JS and CSS files and
// is only needed if you are modifying these core files:
define( 'SCRIPT_DEBUG', true );

Miscellaneous Notes About Logging

There is more to the WP_DEBUG_LOG constant than simply using true or false for its settings. You can use it to define where the log file is. Bear in mind that if you place it in any area of the website that is accessible from the web, anyone will be able to see it. Of course, they do have to know its path from the website’s root directory and they will need to know the file’s name. Also bear in mind that in the Linux environment (as opposed to a Windows environment), file and directory names are case sensitive.

For WP_DEBUG_LOG to function at all, WP_DEBUG must be enabled (true). You can turn the WP_DEBUG_DISPLAY one or off independently by setting it as true or false.

Here is an example of setting it:

define( 'WP_DEBUG_LOG', '/tmp/wp-errors.log' );

Sources

Most of the information here was gleaned various parts of the WordPress.org site at the https://wordpress.org/support/article/debugging-in-wordpress/ page.

CLICK HERE to find your domain name!   CLICK HERE to transfer your domain name!

Archives

Tags

24 hour (1) Accounting (1) Advertising (9) AdWare (1) Alex Johnson (2) Alignment (1) Android (2) Anti-Virus (1) Antivirus (1) Antrim Computer Repair and Service (3) APC Back-UPS (1) Appearance (2) Apple Mail (4) Apple Mobile Mail (2) Attachments (1) Audit (1) Authorized (1) Autoresponder (5) Availability (1) Badges (3) Bank Account (1) Bank Statement (1) Battery Backup (2) Bob Hill (1) Bookkeeper (1) Branding (5) Budget (2) Business (19) Business Management (1) Catalog (1) Charles Oropallo (1) CharlesWorks (37) Cherryl Jensen (1) Chrome (1) Cloud (1) Code (1) Communicating (1) Competition (1) Computer (2) Computer Cache (1) Computer Security (1) Constant Contact (1) Consultation (1) Contact Information (2) Content (1) Content Management (19) Content Management System (1) Copiers (1) Copy Machine (1) Coronavirus (2) Courteous (1) COVID-19 (2) Credibility (6) Credit Card (1) Credit Card Processing (1) CSS (8) Customer Service (2) Design (39) Design Expertise (1) Desktop (1) Dialup (1) DirectAdmin (1) Directions (1) DIVI (2) DNS (1) Do-it-Yourself (1) Documentation (1) Domains (17) Domain Transfers (5) E-Commerce (1) Email (61) Email Lists (4) Email Management (2) Email marketing (3) Etiquette (3) Eudora 6 (1) Exchange (1) Expanding (1) Financial (1) Finish (1) Firefox (1) Fonts (1) Forms (2) Forms Protection (1) Fraud (2) Galaxy S4 (1) General Info (1) Gmail (1) GoDaddy (1) Google (1) Google Adwords Certified Partner (1) Google Chrome (2) Groups (1) Happy Holidays (1) Hardware Help (1) Hill Specialty Networks (1) Hosting (1) Images (1) IMAP (1) include (1) Infected (1) Information (22) insert pages (1) Internet Browsing Errors (1) Internet Consultant (1) Internet Explorer (1) Keywords (2) Laptop (1) Legibility (1) Linux (5) Logging on (1) Macintosh (1) Mail 6.0 (1) Mail 2011 (2) Make-Over (1) Malicious (1) Malware (1) Marketing (6) Matt Burke (3) MDaemon (3) MelbourneIT (2) Merchant (1) Microsoft (1) Microsoft Edge (1) Microsoft Hosted Exchange (5) Microsoft Live (2) Mobile Email Setup (1) Monadnock Region (1) Mozilla Firefox (2) MySQL (1) Nathan Wesley (1) Netscape (1) Netscape Messenger (1) Office Copiers (1) OfficeLive (1) Online (1) Outlook (8) Outlook 2010 (2) Outlook Express (1) PayPal (1) Pay Per Click (2) PC (1) Personal (1) Peter Harris (1) Peter Harris Creative (1) Phishing (2) PHP (2) plugins (1) Pop Email (1) Popularity (1) Portfolio (1) Power Grid Failure (1) PPC (1) Prevent Fraud (1) Privacy (1) Private (1) Product (6) Professional (4) Projects (2) Protect (1) Protection (1) Quality (2) QuickBooks (1) Reconciliation (1) Reduce Risk (1) Register (1) Reliability (2) Renew (1) Reseller (2) Resolution (1) Restrict User Access (1) Results (1) Review (2) Risk (1) Robin Snow (1) Roundcube (1) Safe (1) Samsung (2) Scam (10) Scammer (9) Search (1) Search and Replace (1) Search Engine Optimization (6) Search Engines (9) Security (15) Security Risk (1) Selling (1) SEO (1) Servers (2) Service (8) Shopping Cart (1) Site (1) SmarterMail (9) Social Engineering (1) Social Networking (1) Software (1) Solutions for Today (1) Spam (1) Spam Filtering (14) Spammer (1) Spyware (2) SquirrelMail (1) SSL (7) Statistics (2) Stats (2) Stone Pond Technology (1) Storage (1) Support (1) Tablet (1) Target Market (1) Testimonials (1) The CW Corner (1) Thom Little (1) Thom Little Associates (1) Thunderbird (3) Thunderbird 10 (2) TLD (1) Topic (1) Top Level Domains (3) Transaction (2) Transfer Data (1) Transfer Funds (1) Typography (1) Update (2) Uploading (1) UPS System (2) Up to Date (1) Virus (2) Viruses (1) Vista (1) Web (1) Web-Over (1) Web Development (76) Web Hoster (1) Web Hosting (2) Web Hosting Company (1) Webmail (8) Web Mail (1) Webmaster (10) Web Presence (23) Website (91) Website Development (1) Web Stats (1) Web terms (1) Web Writing (1) Windows 7 (2) Windows Mail (5) Windows XP (1) WooCommerce (2) WordPress (65) WordPress Updates (1) Working Remote (2) Writing (1)