Wordpress Error: What Causes Them and How to Fix Them
If you are encountering a WordPress error message or white screen, don’t panic. Someone has likely encountered the same errors before and it can easily be solved.
Before trying to fix any WordPress error, make sure that you have a complete WordPress backup.
In this article, we will cover the most common WordPress errors along with showing you how to fix all of these common WordPress errors.
Table of contents:
How to check wordpress error logs?
WordPress white screen of death
Internal Server Error
Syntax error in WordPress
WordPress memory exhausted error by increasing PHP memory limit
404 wordpress error
Error Establishing Database Connection
Let’s take a look at how to solve the most common WordPress errors (one by one).
How to check wordpress error logs
Do you need to access the WordPress error logs to troubleshoot a problem on your site?
WordPress comes with a debugging system that can log any error messages displayed on your site. This can help you discover and fix problems on your website.
To begin, access your hosting root directory, where your site is hosted using Cpanel, FTP or Plesk and find the file named wp-config.php which we need to edit to enable debugging.
If you are using Cpanel, once the file is identified, right click it and press the Edit option.
If an encoding warning shows up, press the Edit button again to access the file.
Find the below line and it will be the end of the list.
define( 'WP_DEBUG', false );
Delete it and paste the following lines and then press the Save changes button.
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define('WP_DEBUG_DISPLAY', false );
@ini_set('display_errors',0)
After pasting that code, you can find a new file named debug.log in the wp-content subfolder in your hosting. This file contains every WordPress error message, warning, and notice that has been logged.
In some cases, the debug.log file wasn’t created, but they found a file named error_log within their root directory. If you still want the debug.log file to be created instead of the error_log file, you can rename it and the debug.log file will be created.
This file you will need to download, view, or edit it. You can then inspect the error messages along with the date and time they occurred. This information can help you find a solution to the problems you are encountering on your website.
Note: Some plugins like Wordfence will prevent the debug.log file from being created, you need to disable it until you finish the debugging process.
WordPress white screen of death
The WordPress white screen of death is one of the most common WordPress errors. It is also one of the most frustrating ones because there is no error message, and you are locked out of WordPress.
We will discuss how to fix the WordPress white screen of death by looking at different solutions.
Note: Before you make any changes to your site, make sure you have a backup of your WordPress site.
Most of the time when you see a white screen of death, it means that a script on your website exhausted the memory limit. The WordPress hosting server killed the unresponsive script. That’s why no actual error message is generated, and then you see a plain white screen.
Sometimes you might see a critical error message instead of a plain white screen.
This error can also happen due to a poorly coded theme or plugin installed on your site. Sometimes it can happen if there is an issue with your web hosting server.
If you have other WordPress sites installed at the same hosting account, then you have to check if the problem is occurring on other sites as well.
If it is, something is wrong with your WordPress hosting service. Then you have to need help from a hosting service provider.
On the other hand, if the issue is only happening with one website or a specific part of that site, then you have to know the problem.
If the white screen of death error is caused by a WordPress plugin or theme, then WordPress may be able to catch it.The new fatal error protection feature introduced in WordPress 5.2 can sometimes catch the error. Instead, you will see a message that the site is having technical difficulties.
Increasing the Memory Limit
To fix this, you need to increase PHP memory available to WordPress. This will allow the script to use more memory to finish the job.
Disabling All Plugins
If increasing the memory limit did not help, or if you have a high memory limit like 256M or 512M, then you need to start troubleshooting.
However, if you don’t have access to the WordPress admin area, then you will need to deactivate all plugins via FTP.
First, connect to your WordPress site using an FTP client. Once connected, go to the wp-content folder where you will see the ‘plugins’ folder.
Now, you need to right-click on the plugins folder and then select rename. You can rename the plugins folder to plugins-deactivated.
Your FTP client will now rename the plugins folder.
WordPress looks for a folder named plugins to load all plugins. When it cannot find the folder, it simply deactivates all plugins.
If this fixes the issue, then enable one plugin at a time to get to the bottom of the issue. Once you find the plugin causing the issue, you can replace it with an alternative or report the issue to plugin authors.
Enable Debug Mode to Catch Errors in WordPress
If nothing has helped so far, then the next step is to turn on debugging in WordPress. This will allow you to see what type of errors are being outputted.
Simply, add the following code into your wp-config.php file.
Once you add this, the blank screen will now have errors, warnings, and notices. These may be able to help you determine the root cause.
If you don’t see any errors, you may still want to check the debug log. Simply visit the wp-content folder on your website using an FTP client. There you will find a new debug.log file containing a log of all errors, notices, and warnings.
Clear WordPress Cache
Sometimes, you may have access to the backend, but the front-end of the site has the white screen of death. This can happen because of a caching plugin. Simply empty your cache.
Fixing Longer Articles
If you have a white screen of death only on a very long post or page, then this little trick might work.
This trick basically increases PHP’s text processing capability by increasing the recursion and backtrack limit. You can paste the following code in your wp-config.php file.
Internal Server Error
There can be a number of reasons for an Internal Server Error. Here are some thing you can do to solve it:
The most likely issue is a corrupted .htaccess file. Log in to your site root using FTP and rename your .htaccess file to .htaccess_old. Try loading your site to see if this has solved your problem. If it works, make sure to visit Settings > Permalinks and reset your permalinks. This will generate a new .htaccess file for you.
Try deactivating all of your Plugins to see if it is a Plugin issue. If you are unable to access your WordPress Administration Screens, deactivate your Plugins via FTP by following these instructions.
Switch the Theme to a WordPress default Theme (e.g. Twenty Twenty-One) to eliminate any Theme-related problems. If you are using WordPress 5.8 and below, please switch to Twenty Twenty-One theme since the Twenty Twenty-Two theme requires 5.9 and above.
Increase the PHP Memory limit
Try re-uploading the wp-admin and wp-includes folders from a fresh install of WordPress.
Syntax error in WordPress
This error is caused by an error in the PHP structure when a character is missing or added that shouldn’t be there.
This means the code is missing a character and PHP reaches the end of the file without finding what it’s looking for. The error will include information at the end that explains what it saw that was unexpected.
If you see Parse Error: Syntax Error, Unexpected end in WordPress, it just means that WordPress detected that something in the code is missing or added. It can be something as simple as a comma, semi-colon, a closing parenthesis, or one too many brackets.
How to Solve Parse Error: Syntax Error Unexpected End in WordPress
The actual parse error syntax error unexpected end in WordPress will have a different ending depending on what’s causing the error.
Examples include:
syntax error, unexpected end of fill
syntax error, unexpected token
syntax error, unexpected variable
syntax error, unexpected identifier
The error message will usually identify the specific token, variable, identifier, etc., that it doesn’t like. We’ll see a few examples of this as we go.
Testing the Parse Error Syntax Error Unexpected End in WordPress
WordPress has made lots of improvements in how it handles code. Now, instead of running bad code and killing your website, if it has a previous version of the code that ran, it tries to use that code instead when displaying the site to visitors.
This keeps your site from displaying the error to your visitors and keeps you from being locked out. It is still possible for your site to go down and lock you out, but it’s more difficult now.
Also, the code editors now show markup, so it’s easy to identify variables and other code elements. This makes it easier to test code within the plugin and theme code editors within WordPress.
Unfortunately, WordPress doesn’t always give you a clear message. Sometimes there is no message, content is missing, or it just doesn’t show the website. All of these can be fixed, but they might take a little more troubleshooting.
Let’s look at a few examples. We’ll start with something easy.
Editing Plugin Code
First, start with what you did last. In this example, I’ve edited code in a plugin file. The file reverted to the last known good code, so my changes are not working. Look at the error. It will tell you what’s causing the error code and the line of code with the error.
In this example, WordPress is seeing an unexpected bracket when it’s expecting to see a semi-colon.
This one is simple. First, look at the line above it. We see the word break, ending case 4. We’re fortunate in that we have other cases to compare to. Above it is case 3, which also ends with break, but this one has a closing semi-colon.
Next, edit the code that caused the error.
Here’s another example in the same plugin file. This one is showing the error on line 488. However, that line of code is correct. It’s giving me a clue, though. It’s identifying this as an unexpected variable.
If we look at the code above 488, we see that it’s missing a closing bracket. This causes WordPress to see the next line incorrectly.
Simply add the closing bracket and update the file. The code now works correctly.
These problems were simple, but most of the time you see a parse error syntax error at an unexpected end in WordPress, it’s exactly like these examples.
Debug Mode
The first step is to enable the WordPress error log. Go to your wp-config file using FTP or cPanel. Search for a line of code that looks like this:
If you have this code, change false to true.If you don’t have this line of code, look for a line that says: “Stop editing! Happy blogging.” and paste this code:
Load the website. This will display the error and you now have a place to start troubleshooting.
WordPress memory exhausted error by increasing PHP memory limit
WordPress is written in PHP, which is a server-side programming language. Every website needs a WordPress hosting server for it to function properly.Web servers are just like any other computer. They need memory to efficiently run multiple applications at the same time. Server administrators allocate specific memory size to different applications including PHP. When your WordPress code requires more memory than the default allocated memory, you get to see this error.
By default, WordPress automatically tries to increase PHP memory limit if it is less than 64MB. However, 64MB is often not high enough. Having said that, let’s see how to easily increase the PHP memory limit in WordPress to avoid memory exhausted errors.
Increase PHP Memory Limit in WordPress
First you need to edit the wp-config.php file on your WordPress site. It is located in your WordPress site’s root folder, and you will need to use an FTP client or file manager in your web hosting control panel.
Next, you need to paste this code in the wp-config.php file just before the line that says ‘That’s all, stop editing! Happy blogging.
This will update your permalinks settings and flush rewrite rules. In most cases this solution fixes the WordPress posts 404 error. However, if it does not work for you, then you probably need to update your .htaccess file manually.
Login to your server using FTP, and modify the .htaccess file which is located in the same location where folders like /wp-content/ and /wp-includes/ are located. The easiest thing you can do is to temporarily make the file writeable by changing the permissions to 666. Then repeat the original solution. Don’t forget to change the permissions back to 660. You can also manually add this code in your .htaccess file:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Error Establishing Database Connection
The ‘Error establishing a database connection’ issue can be caused by incorrect database information in your WordPress settings, corrupt database, or an unresponsive database server.
A database is a software which makes it easy to store, organize, and retrieve data into other software.
As a content management system, WordPress uses a database to store all your content and other website data. It then connects to the database each time someone visits your website.
WordPress needs the following information for connecting to the database:
Database name
Database username
Database password
Database server
This information is stored in your WordPress configuration file called wp-config.php.
If any of these items are incorrect, WordPress will fail to connect to your database server, and you’ll see the ‘Error establishing a database connection’ error.
In conclusion, We have covered some of the most common WordPress errors in this article. However, the real power of WordPress comes from thousands of plugins and themes that you can use on your site. Any plugin or theme installed on your site can cause errors.
It could become really hard for beginners to find out what is causing the problem on their site and how they can fix it.
0 Comments
Thanks for Comment