See Logs in WordPress, detecting errors –

Working with WordPress implies going through processes or phases in which we have to debug errorssome produced by the use of incompatible or outdated plugins or themes that affect the operation of the website and others caused by ourselves in the desire to make improvements or add new features.

Don’t be pushy and use one or work on one before messing around with the file functions.php

Hosting Mautic QuickStart -50% with support in Spanish
24 hours and free training

Send up to 1,000,000 emails/year. Mautic support in Spanish 24 hours, 365 days

Whatever your reason for having to consult the error files or logs, I want to tell you that in addition to being important to know how to locate and interpret them, you should see them as an ally in your task of managing and maintaining a WordPress site in perfect health.

Just understanding that the information that error log They give you are the clear indicator of a problem and the starting point to solve it, you will come to the conclusion that!the logs are there to help you and make troubleshooting easier!

Diagnosing WordPress issues, especially for non-technical people, can be a very daunting job.

Error handling from wp-config.php

Perhaps the easiest way to implement a PHP error handling adding a few simple lines of code in the file wp-config.php.

You can create an empty file called php-errors.log. This file will serve as your site’s PHP error log. The server will have write access to this file (set the appropriate permissions for it).

See also  URL to show part of my website in an iframe of another

This file can be placed in any directory, but placing it above the root /public_html directory of your site will not make it accessible from the browser. Once this file is created, with write permissions, make a note of the absolute path, for example: /home/user/tmp/php-errors.log in this way you will have write permissions but it will not be visible via the web.

Then open the file wp-config.php of your site (located in the root directory of your WordPress installation) and place the following code immediately above the line that says:

/* That’s it, stop editing! Happy blogging */

The code to insert is:

// php error log @ini_set(‘log_errors’,’On’); // enable or disable php error logging (use ‘On’ or ‘Off’) @ini_set(‘display_errors’,’Off’); // enable or disable public display of errors (use ‘On’ or ‘Off’) @ini_set(‘error_log’,’/home/testw/tmp/php-errors.log’); // server log file path with writable permissions

Note: you will need to change /home/testw/tmp/php-errors.log to your path to the quoted file.

From now on all PHP errors will be recorded in this file, allowing you to review and resolve errors having specific information at your fingertips.

You must add the following defines in the file wp-config.php and WordPress debugging errors will be written to the file php-errors.log.

define(‘WP_DEBUG’, true); // Enable debug mode define(‘WP_DEBUG_LOG’, true);

Most WordPress installations already have an entry for WP_DEBUG set to false so you will have to change this value to true (real). It is not so common to have WP_DEBUG_LOG already established in wp-config.php and you will most likely have to add that line.

See also  Best WordPress Sitemap Plugins

Testing, testing, 1 2 3…

An easy way to test that your error logging system is working is to fire some basic PHP errors. For this you can go to Appearance, Editoredit the theme functions file functions.php and add some code that triggers an error, for example:

Eye!!! Don’t do this on a web “in production” as it will no longer be accessible immediately. Only for tests from a “sandbox” or in a copy of your website.

The result of the error collected by the file php-errors.log will be similar to the following:

You solve it by editing the file /public_html/wp-content/themes/your_theme_in_use/functions.php of your Theme in use and removing the code added at the end. You save the changes and your website will be operational again. 🙂

If you are generating errors but they are not written to the log file php-errors.logverify that the file has write permissions (normally 644) and that it is in the appropriate folder of your Hosting.

Plugin to detect errors in WordPress

A plugin that you can use to analyze errors from the dashboard and without having to figure out where to locate those files error_log, php-errors.log or check the error logs of your WePanel hosting panel, it is the plugin called Error LogMonitor.

You install it, activate it and you will see a widget on the dashboard desktop that will collect the PHP errors that arise in your active installation.

For it to work you must insert this define in the file wp-config.php of your WordPress installation, before the text /* That’s it, stop editing! Happy blogging */:

ini_set(‘log_errors’, ‘On’); ini_set(‘error_log’, ‘/home/testsw/public_html/wpencelado/php-errors.log’);

See also  multi language bug

Note: The path of ‘error_log’ must be relative to the location of your file php-errors.log.

Knowing the location of the bug files and knowing how to interpret them properly or searching the Internet for the error found in your error log, you will have everything you need to keep a better control of errors that occur, which will allow you to ensure a WordPress website with good performance giving a better user experience for your visitors.

Help us improve our content by sharing your opinion

Member of the technical support team.
Coordinator of contents in the Blog and in Youtube.
Technical support in CyberProtector. Teacher at University

Loading Facebook Comments ...
Loading Disqus Comments ...