Skip to main content

Practical Guide: How to Fix Common Errors in WordPress

WordPress is an extremely flexible platform, but you may run into errors that affect its operation. In this article, we will take a step-by-step look at solutions to resolve the most common errors, providing practical directions and sample code to help you restore your site quickly and easily.

Enabling Debugging

To identify the source of errors, it is essential to enable WordPress debugging. To do so, edit the wp-config.php file by adding the following lines:

define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );
@ini_set('display_errors', 0);

This way, all errors will be logged in the wp-content/debug.log file, allowing you to analyze them in detail.

Disabling WordPress Plugins

Disabling Plugins via shell

Plugins are often the cause of conflicts. To check if they are causing problems, rename the plugins folder:

mv wp-content/plugins wp-content/plugins-disabled

If the site returns to working properly, the problem may lie in one or more plugins.

Disable plugins with phpMyAdmin

If you can't access the backend, you can disable plugins via the database:

  1. Log in to phpMyAdmin and locate the wp_options table.
  2. Search for the row with option_name equal to active_plugins.
  3. Modify the option_value field by setting it to a:0:{}.

This procedure will disable all active plugins.

Resolving Errors in WooCommerce

In case the problem is related to WooCommerce, rename the specific directory:

mv wp-content/plugins/woocommerce/plugins wp-content/plugins/woocommerce/plugins-disabled

This allows you to figure out if the problem is coming from the WooCommerce plugin or one of its extensions.

Restore a Default WordPress Theme

Sometimes the active theme can cause conflicts. To test this hypothesis:

  1. Go to wp-content/themes.
  2. Copy the default theme (e.g., Twenty Seventeen) to another directory just in case.
  3. Remove it from the folder and activate the default theme.

This will help determine if the error is related to the theme in use.

Debug Extensions

For more in-depth diagnostics, consider using specific debugging plugins, such as:

  • Query Monitor
  • Debug Bar

These tools provide detailed information about queries, PHP errors, and other issues, making it easier to find the cause.

Managing WordPress Heartbeat

The Heartbeat API, which uses the admin-ajax.php file, may generate HTTP 503 errors. To temporarily disable it, add the following code in the functions.php file of your theme:

add_action( 'init', 'stop_heartbeat', 1 );
function stop_heartbeat() {
    wp_deregister_script('heartbeat');
}

This helps to reduce the load on the server in case of API-related errors.

Increase PHP Memory

If your WordPress site shows errors such as the 500 internal server error, try increasing the memory allocated by WordPress by editing the wp-config.php:

define ('WP_MEMORY_LIMIT', '128M');

This can solve memory depletion problems. Advise: Contact your hosting to increase the global limit if necessary.

Update WordPress Core

If none of the above solutions solve the problem, the error may lie in the WordPress core files. If this is the case:

  1. Download a new copy of WordPress from the official website: https://it.wordpress.org/.
  2. Replace the wp-admin and wp-includes folders on your server with the ones you just downloaded.

This operation ensures that the system files are intact and up-to-date.

Frequently Asked Questions (FAQ)

D: How do I enable debugging in WordPress?
R: Edit the wp-config.php file by adding lines to enable WP_DEBUG, WP_DEBUG_LOG and disable WP_DEBUG_DISPLAY.

D: What can I do if WordPress shows an error 500?
R: Besides increasing PHP memory, try disabling plugins and updating WordPress core files.

D: How can I detect if a plugin is causing problems?
R: Rename the plugins folder via FTP or File Manager to disable all plugins and see if the error persists.

D: What is WordPress Heartbeat and how to manage it?
R: It is an API for monitoring site activity; it can be disabled by adding a specific code in the functions.php.

For more in-depth information, check out the official documentation.

Following these steps will enable you to effectively detect and fix common errors in WordPress, ensuring the stability and performance of your site. If you need professional assistance, our team at Linux and Cloud Consulting is at your disposal.

Add new comment

Comment

  • Allowed HTML tags: <br> <p> <code class="language-*"> <pre>
  • Lines and paragraphs break automatically.
  • Only images hosted on this site may be used in <img> tags.