Dealing With PHP Issues

And Breathe

When it comes to troubleshooting technology, everyone loves the tried-and-true methods of rebooting or hitting it really hard. Unfortunately, those solutions don’t help much when dealing with PHP issues on your WordPress site. 

In this post, we’ll look at some of the most common PHP errors that occur on WordPress sites and how to fix them.

PHP and WordPress

WordPress is primarily written in PHP. This means that each time your website is rendered, it requires PHP to run WordPress core, as well as any WordPress plugins and themes.

Like any other software, PHP is continuously evolving. Each new version introduces various changes, such as performance improvements, security enhancements, and new functionality. While most WordPress plugins and themes are great at keeping their code compatible across PHP versions, incompatibility with certain versions, especially old ones, can sometimes introduce bugs.

Which Version of PHP is Best for WordPress?

As of Version 6.3, WordPress recommends sites use PHP Version 7.4 or greater. The release of WordPress 6.3 also ended support for PHP 5.

You want to use newer versions of PHP because they’ll be faster and more secure. Read our post on why PHP versions matter to learn more about the benefits of keeping your PHP version up-to-date. 

How to Find WordPress PHP Version

To see the PHP version and settings for your site, log in to the WordPress admin, then: 

  1. Click on Tools and Site Health.
  2. Click on the Info tab at the top of the screen.
  3. Scroll down and expand the Server section. 

Updating PHP Versions

Taking the time to make sure all parts of a website are updated and compatible with the newest version of PHP will save everyone from a lot of sleepless nights. We recommend three core actions before executing any PHP updates.

1. Check Your Version of WordPress

Don’t think that if you update one, you won’t need to update the other. Having an outdated WordPress site try to run an up-to-date PHP is a clear path to disaster. For customers using Pressable’s managed WordPress hosting service, know that you’ve already been updated to the most recent version of WordPress.

Prior to performing any updates, be sure to make a backup of your site before making any changes. That way if any issues occur from updating WordPress, you can reload that backup and figure out the problem. Once WordPress has been updated, you can move onto checking everything else.

arrows pointing to a backup icon

2. Check Themes and Plugins for Updates

This step can be a little more tedious than the first. You’ll need to look through both of these to make sure they’re running on up-to-date versions. If there are any updates available, make a backup, then complete those updates.

Good news: If you’re using Pressable’s managed plugin update features, backups and testing are already handled for you during each plugin update.

If you’ve been neglecting maintenance for a while, keep an eye out for any plugins that haven’t received an update within a year. It’s incredibly likely that these are not compatible with a newer PHP version and will ultimately break your website.

Another thing to pay attention to is themes/plugins that have paid licensing that are expired and haven’t updated. If you’ve let a premium plugin’s license lapse, it’s possible that these plugins aren’t showing as having an update available.

Now, with this all sorted, you can find alternative plugins for those that are outdated and then move on to checking the last part of your website.

3. Review Any Customizations

If you had a developer make a custom theme or plugin for you, we recommend getting in touch with them to review if it will be compatible with the update. If not, you will most likely have to review an alternative option, to keep your website running smoothly once updated.

With these preparations in place, you’re ready to make the switch to a new version. From here, you can actually test to see if your site will run on the new PHP on a staging site. 

Back up your live site, copy it into a staging environment, and test out the newer version of PHP. If all goes well, you are good to upgrade your live site!

Identifying PHP Errors

If you’re running updated versions of PHP and WordPress and still getting an error, the first step is figuring out what the error is. Your web server’s error log will record any PHP errors. 

Pressable customers can find their error log by logging into My Pressable and selecting the site they want to review. Do this by clicking the Logs tab and PHP Logs. Click the Get Latest button to see the recent errors. 

Common PHP Issues 

It’s possible to see a variety of PHP errors on your site. Let’s take a look at the most common ones you may encounter.

Some of the most frequent PHP errors and issues with WordPress include:

  • White Screen and Fatal Errors. Everyone hates the screen of death. It occurs most often after an update. Sometimes, WordPress will send an email to your site administrator detailing what the error is. In most cases, it’s a PHP error with a plugin or theme. 
  • Themes or Plugins Not Working. If a theme or plugin isn’t working, odds are it’s a problem with the PHP code in the files. 
  • Version Compatibility. If you’re using depreciated functions or a plugin was built with a different version of PHP, you’ll end up with an error. 
  • Memory Errors. A poorly coded plugin or otherwise heavy script could cause a memory issue. For example, looping through too many posts or products could cause the function to time out before it’s completed. 

Fixing Common PHP Issues on Your WordPress Website 

If you’re dealing with one of these common PHP errors, don’t panic. None of the errors that caused this are any that can completely wipe your website off of the face of the internet. 

In most instances, one of the items listed above is responsible. If you have a backup from before the update when live on the site, great! Reload that backup and work from there. 

No backup? Consider this a valuable learning opportunity of the importance of doing so before updating core code. Then, take the following steps to repair the issue.

1. Increase Your PHP Memory Limit

Start by increasing your PHP memory limit. Some cheaper hosting plans set extremely low defaults. That’s not the case with Pressable. You can learn more about our PHP settings and limits here

2. Update WordPress

This step isn’t any different from earlier. Make sure WordPress is up to par before moving on. Complete the manual update and check your site. Is it working now? Great, you’ve probably solved the issue. To be on the safe side, we suggest you make sure everything else is updated. If your site is still not working, continue to the next step.

3. Deactivate all Plugins

A deactivated plugin isn’t a deleted one. You’ve simply paused the interaction between the plugin and your site. Once you’ve done this, go check on your site. If things seem to be running smoothly, skip the next step. If not, continue on.

arrow pointing to a deactivation link on a WordPress plugin

4. Change to the Default Theme

Outdated themes can cause a lot of issues. Temporarily switch your site to the standard WordPress theme to allow a new PHP to get along with your website. After this, your site should be running fine, although it’ll look a little different. Log back into the admin side of WordPress to continue.

5. Update Everything

Run all the updates. Yes, everything. All plugins and themes. Be sure to check whether you need to remove anything that you don’t need or hasn’t been updated within a year.

6. Activate Plugins and Themes

Once everything is updated and unneeded items are gone, start turning things back on one by one. Be sure to check your site after every change to make sure it’s still in working order. If your site breaks after a specific change, you caught the culprit red-handed! Deactivate it once again and search for a replacement, as it is no longer compatible with PHP.

Other PHP Errors and How to Fix Them

Updating everything and manually turning on and off plugins is the best way to troubleshoot the most common problems with PHP and WordPress. It’s like using a broad-spectrum antibiotic. It covers most of what could go wrong. For more specific error messages, try these solutions. 

Cannot Modify Header Information

If you get a message that WordPress can’t modify header information and headers are already sent, the likely cause is characters or spaces before your opening tags or after the closing tags. The WordPress documentation walks you through how to fix this issue. 

Call to Undefined Function

This error message most likely means a plugin is trying to find data or a file that doesn’t exist or isn’t accessible. Start by following the update and troubleshooting steps from earlier. If that doesn’t solve the issue, check your functions.php file for any misspelled functions. 

Syntax Error

Sloppy code is the most likely cause for this error. The good news is that it’s also the easiest to fix. WordPress will typically tell you which file and the line number the error occurred in. You’ll need to access the file and fix the code. 

Unexpected

If you see “parse error: unexpected” you’re likely just missing a character. For example, if you get Unexpected ‘)’, you probably just forgot to include an opening bracket (.

Use of an Undefined Constant

The two most common reasons you’d see this error are if you forgot to include a $ when referencing a variable or if you’re missing quotation marks around array keys. 

Best Practices for PHP and WordPress to Avoid Issues

They say a good offense is the best defense. It’s true where PHP issues are concerned. The best way to handle PHP errors is to avoid them in the first place. 

To avoid PHP errors on your WordPress website, follow these best practices:

  • Stay Updated. Keep all plugins, core files, and themes up-to-date. Ensure your server is running off a new and supported version of PHP. 
  • Be Careful with Custom Code. Don’t use deprecated functions, and make sure you validate your code on a tool like PHP Code Checker
  • Use a Staging Site. If you’re using a new plugin or want to prepare for a new version of PHP, use a staging site. You can make sure everything works before making changes to your live site. 
  • Use an Alternative. If PHP isn’t your thing, consider using an alternative. The WordPress REST API offers access to WordPress data without having to write any PHP. 

Additional PHP Resources

Dealing with PHP issues is not a walk in the park. To make your job a little easier, we’ve compiled a few helpful resources:

If you’re new to Pressable, check out these support articles to learn more about how we handle PHP:

We’re Here If You Need Us

No one likes dealing with PHP issues. The good news is you won’t have to if you keep things updated and are careful with your plugin selections and use of custom code. 

When something does go wrong, the Pressable team is here to help. When you host with Pressable, you get automatic updates to WordPress and PHP. We also include free staging environments so you can test things out without your customers (or your boss) seeing something if it goes wrong on the first try. 

Want to test us out? Request a free demo.

Brenda Courtney

Guest Author

Brenda Courtney is the SEO specialist and main content creator for innov8 Place. She enjoys the challenge of writing and researching the ways to appease Google in the modern world. In her spare time, she writes more for herself and is probably listening to a true crime podcast.

Related blog articles