How To Fix WordPress

WordPress generally runs smoothly, but as with any system, things can go wrong.

There are some common fixes that will solve most of the problems you'll encounter.

how to fix WordPress

How to fix WordPress:

Bonus fixes:

Turn on debugging

In the wp-config.php file, you should see this line:

define('WP_DEBUG', false);

Change it to:

define('WP_DEBUG', true);

Save the file on the server and retry your website.

If you're lucky, you'll get a specific error like this:

If you look at the second half, you'll see there's a problem on line 10 of the functions.php

This close, but the problem isn't actually on line 10. It's on the line above. You'll find the "unexpected" type errors is usually because you've forgotten a semicolon or a bracket.

The problem code here is missing a semicolon after false:

But at least it gives you a good idea where to look.

If you have a fixed header, the error message might be hidden under that. It could also be hidden underneath the WordPress Admin bar. If you suspect either might be the case, right click and view source.

How to log WordPress errors

If you are working on a live site that gets a lot of traffic and you don't want to display the errors, you can log the errors to a file.

Add this code to wp-config.php:

define ( 'WP_DEBUG', true );
define ( 'WP_DEBUG_LOG', true );
define ( 'WP_DEBUG_DISPLAY', false );

Save the file and then instead of the errors being visible to visitors, they will be logged to a file called debug.log in /wp-content/.

This is also useful where you have a complex step system giving problems, such as WooCommerce, or where you're only sometimes getting errors.

Check for a .htaccess problem

If you can't log in to the site, I find it's almost always either because of a broken plugin or a problem with the .htaccess file.

You read that right. It's [dot]htaccess - no initial filename.

.htaccess is how most servers figure out things like virtual folder structure.

It often handles redirects and other server level things.

If you have to edit the .htaccess file, make absolutely sure that you have a copy of your current one on your computer.

The way I usually edit .htaccess is to copy it to my computer, then copy it again to the server. Rename the copy to something like .htaccess_old.

If you can't find the .htaccess file, it might be hidden, or it might not actually be there. If you're accessing the files via FTP or sFTP, it's highly unlikely the .htaccess file is hidden. It's usually only an issue if you're accessing the files through the cPanel File Manager on some hosts.

How to show hidden files in cPanel File Manager:

  1. Click on "Settings"
  2. Make sure Show Hidden Files (dotfiles) is checked
  3. Click "Save"

If there is no .htaccess file in the main folder (where you see wp-admin, wp-content and wp-includes) and you're running a regular WordPress site (as opposed to a Multisite), create a new file called .htaccess and add this code to it:

# 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

Save it and try the site again.

If there is a .htaccess file in the main folder, copy it as I outlined above. It might have a whole lot of lines added by a security plugin or a caching plugin.

Once you're sure you have backups of the file, try changing it to the default WordPress .htaccess code listed above.

Yes I'm paranoid about the contents of the file, because I've seen people loose whole sites over it and it can take dozens of expert hours to fix.

Check the PHP version

One of the first things you should check right now is the PHP version. PHP versions below 7.0 stopped being supported at the end of 2018.

Given pre-7.0 code is no longer officially supported, some developers have started using PHP 7+ functionality, which isn't backwards compatible.

The fastest way to check the PHP version is to create a file called phpinfo.php in the main folder of your website (where you see wp-admin, wp-content and wp-includes). Add this code to that file and save it:

<?php
phpinfo();
?>

Then open the file by browsing to http://yourdomain.com/phpinfo.php

You'll see something that looks like this:

The PHP version is at the top. The rest is details about your server, what extensions it has, etc.

Once you've finished with the phpinfo.php file, be sure to delete it off the server. If someone thought to look for it, they might get some ideas about where your server might be vulnerable to a hacking attempt.

I've got a full tutorial on how to upgrade the PHP version here, so I won't go over it again in this post. I've also covered the individual steps with some of the most prominent hosts, so be sure to find yours and follow the steps.

Check the WordPress memory limit

Some plugins and themes are fairly resource intensive. They might need a minimum of 64MB of memory.

The default WordPress memory is 32MB, so there's a good chance you'll need to increase it.

If you don't have an entry in wp-config.php (see below), the fastest way to check a site's memory limit is to pull it in with a shortcode.

Set it up with this code in your functions.php file:

function memory_check_func() {
  return "Memory limit is: " . WP_MEMORY_LIMIT;
}
add_shortcode('memory_check', 'memory_check_func');

Then just add this shortcode to a test page:

[memory_check]

You'll see something like:

Memory limit is: 32M

The quickest way to increase the WordPress memory limit is:

  • Edit wp-config.php
  • Look for the line
    • /* That's all, stop editing! Happy blogging. */
  • Directly above that line, add
    • define('WP_MEMORY_LIMIT', '64M');
  • Save wp-config.php

If you want to increase the memory limit to 128MB, change 64M to 128M.

Increase The Execution Time Limit

Sometimes things just need a bit longer to run. WordPress might throw an error like "Maximum execution time of 30 seconds exceeded".

If you get an error that seems like it could be a time limit problem, try increasing the Maximum Execution Time.

There are a couple of ways to do this. You just need to pick one.

All of these methods will change the maximum execution time to 120 seconds (ie two minutes). If you want a different time limit, just change that number.

If you set the time limit too large, it can cause processes to get stuck and grind your server to a halt. I wouldn't go more than 300 seconds.

Edit wp-config.php

Edit wp-config.php, adding the following code just above /* That's all, stop editing! Happy blogging. */

set_time_limit(120);

Edit .htaccess

At the top of the .htaccess file, add this code:

php_value max_execution_time 120

Edit php.ini

In php.ini, look for max_execution_time and change the number after that.

If it has a semicolon before it, remove that. The semicolon is a "comment" in php.ini.

You probably won't have access to this if you're on a shared host environment.

The line should look like this:

max_execution_time = 120

Sometimes, you just need to give the Permalinks a bit of a kick. I've never figured out exactly why it works, but it's worked often enough that I always give it a try.

You're not changing permalinks, simply saving them.

  1. Navigate to Settings -> Permalinks
  2. Scroll to the bottom and click "Save Changes"
  3. Wait til you see Permalink structure updated

Clone the site to a development server

If these changes don't solve your problem, it's probably best to setup a development server and run further tests there.

Sometimes, especially on shared hosting, hosts change settings without telling their customers.

I've had instances where the host switched my site to a different server because the first failed.

It's annoying and shouldn't happen, but it does.

Check out this tutorial on how to copy a WordPress website to a development server.

Update WordPress, Plugins and Themes

Keeping your site up to date is important. Doing so plugs security issues, fixes bugs and allows you to access the latest developments.

If you have let your site go for a bit and there is a lot of updates needed, don't just update everything on your live site and hope for the best. Make sure you copy the site to a development server and check that the updates won't break anything.

And of course, backup, backup, backup.

Disable all the plugins and switch to a default theme

Don't do this on a live site that might be getting visitors. People coming to your site will have a horrible experience if you do. Make sure to do this on a development server.

If WordPress is still not fixed, it's time to get more drastic.

You need to disable all the plugins and switch to a default theme.

How to disable all WordPress plugins:

  1. Navigate to Installed Plugins
  2. Click the checkbox in the top or bottom row to select all the plugins
  3. Choose Deactivate
  4. Click "Apply"

How to disable WordPress plugins when you can't get into the WordPress admin area:

  1. Log in to where you can edit the files on your server (FTP or in cPanel)
  2. Navigate to wp-content -> plugins
  3. Rename each of the folders by putting a 1 at the end

Renaming the plugin folders will automatically disable them when you refresh your site. The same goes for themes.

You should now be able to login and make changes.

Just be sure to change the folder names back to what they were originally, so there are no issues with updating them later.

How to switch to the Twenty Nineteen WordPress theme:

  1. Under Appearance, click Themes
  2. Hover over the Twenty Nineteen theme
  3. Click "Activate"

If this fixes the problem, you have a plugin or theme conflict.

To resolve the conflict, enable one plugin at a time, checking each time if it triggers the problem.

If after activating a plugin or theme, the problem comes back, that plugin or theme has the conflict.

Depending on the plugin or theme, you might want to replace it with another plugin that does a similar function, or try a different theme.

It's probably best to also get in touch with the developer of the conflicting plugin.

WordPress Stuck in Maintenance Mode

When you update WordPress, plugins or themes, your site is automatically put into maintenance mode. You might have seen this:

Sometimes the site gets stuck during the update. Usually because it's timed out. If so, you might see this when you access the site:

Thankfully, this one is really simple to fix. There's a file that's blocking the ability to display the site.

How to fix WordPress stuck in Maintenance Mode:

  1. Navigate to the root folder on the server
  2. Look for a filed called .maintenance
  3. Delete that file

If you can't see .maintenance, make sure hidden files aren't hidden. See the section above on how to unhide dotfiles.

Error 500: WordPress Database Connection Error

Thankfully, WordPress database connection errors aren't as common as they were maybe five years ago.

I've found that most of the time, it's caused by a plugin conflict. Read how to fix that above.

If you're sure it's not a plugin conflict, check the database login in wp-config.php. You'd be surprised the number of times that gets missed when you're copying a site over.

Also try the .htaccess fix above.

If none of these work, there's probably an issue with the host. You're best to put in a support ticket with them at this stage.

Point the URLs to the correct domain

Sometimes, when you migrate a website, not all the links now point to the new domain.

If you've moved from a local installation to a website, everything might look fine to you, but no one else can see the pictures. That's because they're actually pointing to your computer. As no-one else has access to your computer, they can't see the images.

Make sure you run this whenever you change domains or domain configurations.

My preferred way to fix this is with a free plugin called Velvet Blues (yes I'm aware how strange the name sounds).

You don't need to keep this installed or active. Just install, use as needed, then remove.

Just search the WordPress repository in the usual way, and install this one:

To find it, look for Update URLs under Tools in the sidebar.

Make sure you backup your database at this point. It's easy to make a mistake and break all the links on your site.

Put the old URL in the Old URL field and the new URL in the New URL field.

Make sure they both have a slash at the end, or both don't have a slash at the end. Otherwise you'll break all the URLs and have to roll back.

Check everything except the last field, then click "Update URLs NOW".

You should see a Success notification telling you what has been updated

If nothing needs updating, you might see what looks like an error message, but if you've written the Old URL correctly, it's nothing to worry about.

I also use this when I switch from http to https or between www and non-www.

Nothing happens when you make changes

It can be a little frustrating when you make changes to your website, refresh the page... and nothing happens.

Sometimes the page doesn't save when you hit update. You should get an error message if that's the case. Most of the time, that will be caused by a plugin conflict. And that plugin will almost always be the caching plugin, in my experience.

If you're sure the page is saving, do you have a caching plugin? Something like W3 Total Cache, WP Rocket or Super Cache? If so, you may need to manually clear your cache.

There will usually be an item called "Performance" or "Cache" on the Admin Toolbar. Hovering over that will show a dropdown menu. One of those items should be something like "clear the cache" or "purge the cache".

See our full tutorial on clearing your cache in WordPress.

Basically, what's happening is the caching plugin is telling WordPress to serve up a stored copy of the page, rather than rebuilding the whole page every time it's accessed. This is great for speed, but it can cause issues when you're trying to design.

I always turn off any caching plugins when I'm designing a site.

If neither of these fixes the issue. You might have caching at the server level. Most servers are intelligent with that, but I've had the odd glitch. Cloudflare has a development mode or a cache clear button, as does SiteGround and many others.

"Another update is currently in progress" Error

If something happens while you're updating WordPress, you can get stuck with an error message and can't continue updating.

How to fix "another update is currently in progress" error message: Wait for 15 minutes and it will clear itself. Otherwise, go into wp-options, sort by largest ID and find the option_name "core_updater.lock". Delete that row and the problem will be fixed.

I was updating to WordPress 5.1 and the update timed out.

I increased the maximum execution time, refreshed and got this screen:

I went into wp_options and deleted the row with "core_updater.lock" as shown (this is in MariaDB):

The option value is a timestamp of when you started the update. That's how WordPress knows to clear it after 15 minutes.

I restarted the Update process and it went through fine:

"You cannot delete a plugin while it is active on the main site" Error

If you have deactivated a plugin and tried to delete it, sometimes it will get stuck and come up with an error.

How to fix "You cannot delete a plugin while it is active on the main site" error:

Deactivate the W3 Total Cache plugin, delete the plugin that you were trying to delete, then activate the W3 Total Cache plugin.

This error doesn't happen all or even most of the time, in my experience. It seems that occasionally something gets stuck between the caching and the plugin telling WordPress that it is no longer active.

If you don't have the W3 Total Cache plugin installed or active, then check your other caching plugins or clear the server cache. I've only ever seen this happen with W3TC, but that's not to say it can't happen elsewhere.

Mike Haydon

Thanks for checking out my WordPress and coding tutorials. If you've found these tutorials useful, why not consider supporting my work?

Buy me a coffee

1 thought on “How To Fix WordPress”

Leave a Comment