Blog

Fix “Parse error: syntax error, unexpected T_FUNCTION”

lines of HTML codes
Need help with your WordPress Project? Hire an experienced developer today!

Many times, when installing a new plugin or theme, you may encounter the Parse error: syntax error, unexpected T_FUNCTION error. This error is basically indicating you that there’s something wrong in one of your functions.

Most of the times, you should also get the exact located of where the error actually appears – Parse error: syntax error, unexpected T_FUNCTION in /public_html/wp-content/themes/custom-theme-name/functions.php on line 123.

Fixing the “Parse error: syntax error, unexpected T_FUNCTION” Error

There are multiple ways in which you could fix the “Parse error: syntax error, unexpected T_FUNCTION” error. We’ll explore the different methods here, but first, let’s discuss the actual origin of these errors. Basically, the T_FUNCTION error appears whenever there’s some syntax errors within your plugin or theme files. It can either be a non-valid part of your code, or alternatively the plugin or theme is trying to use features of a more advanced PHP version than the one actually installed on your server.

Method 1: Upgrading Your PHP Version (Recommended)

This method would be the best way to solve the “Parse error: syntax error, unexpected T_FUNCTION” error. Specifically if it really originates from a use of new PHP features while you are running an outdated version. Running an updated PHP version could both solve these errors and upgrade your performance, so it’s a double win for you!

Most hosts would allow you to manually change the PHP version via the cPanel:

  1. Log in to your hosting provider cPanel
  2. Look for the PHP Configuration button
  3. Manually select the a newer PHP version. We recommend PHP7 if available, but otherwise try to make sure it’s 5.4+

If you don’t have access to the cPanel, or prefer that the hosting provider deals with it, you can try contacting them by email with the following message:

Hello,

I’m an admin of a WordPress site hosted on one of your servers. Unfortunately, I get many errors due to my outdated PHP version. I’ll deeply appreciate if you could help me upgrade my PHP version to PHP7 if you support it. Otherwise, 5.4+ would be also acceptable.

Can you please let me know if it would be possible to upgrade my PHP version?

Your help is much appreciated.

Method 2: Deleting the function located in the error message

As mentioned above, you can usually see the exact path of the error – Parse error: syntax error, unexpected T_FUNCTION in /public_html/wp-content/themes/custom-theme-name/functions.php on line 123..
Now, you can browse to the full path by using an FTP Client, and edit the file mentioned in the error (in our example, it is the functions.php file, on line 123). Then, check the function or the few lines of code that are located there, and comment them out. This should work well for non-important functions. Unfortunately in case we deal with core features of your theme/plugin you will have to use Method 1 and upgrade your PHP version.

 

If you need a savvy WordPress developer to help you out, please consider Hiring an Expert.



Scroll to top