parallax background

How To Fix The WordPress Parse Error Easily

How to Fix the “Currently Unable To Handle This Request” Error
February 12, 2021
How To Remove the Category From the WordPress URL
February 15, 2021
 

A WordPress parse error is serious. It will block access to the website and readers won’t be able to view the content.

Some common syntax errors are:

  • "parse error: syntax error, unexpected t_string wordpress"
  • "syntax error unexpected end of file"
  • "syntax error, unexpected t_function"
  • "syntax error unexpected text t_string"
  • "parse error syntax error unexpected if t_if wordpress"

Fortunately, they are not difficult to fix. It’s usually possible to see from the error log what caused the malfunction.

The key is to identify the corrupted file and change it.

Before restoring the site, site owners need to understand what a WordPress parse error is and what may have caused it.

Outlined below are some useful tips for fixing the error.

Types of WordPress Parse Error

First of all, what is parsing? Parsing is a process of interpreting a string of data and converting it into a different format.

It means that the code which holds the website data is converted into the content displayed on the page.

A parse or syntax error occurs during this process of data transformation. It indicates that there is a mistake in the PHP script.

This may be due to a faulty coding structure, punctuation, incorrect function names, or invalid variables.

WordPress parse errors usually occur after making changes to the website. It could be a problem in a plugin, theme, or core file.

A recent modification of any of the WordPress files, especially core files, is the likely source of this error.

Take care when inserting the code characters. Even a small typo or a missing part of the code will cause a syntax error and make the script impossible to process.

When there's an error in the code, the PHP parser cannot interpret the code and stops working. Consequently, the data will not display on the page.

It’s usually easy to trace the cause of the issue. Generally, there are three types of parse error:

Syntax error

 

This error indicates that there is a mistake in the code. The error log will pinpoint the exact line of code where the error occurs.

It's often caused by a missing PHP tag at the beginning or the end of a block of code. Another source of the problem could be the semicolons, curly brackets, or quotations.

Unexpected error

 

The 'unexpected error' points to something that has failed to close. Somewhere in the code, there might be a missing opening or closing bracket, or another character.

The PHP parser reached the end of the script without finding the information it was looking for. This triggered the error message.

Undefined constant error

 

A constant is a simple value that can't change later. Whenever PHP has detected that an undefined constant has been used, it will send this error.

It can be due to a missing character.

Tracing the Source of the WordPress Parse Error

In most cases, fixing a syntax error isn't complicated. Unlike other malfunctions that are hard to diagnose, this should be straightforward.

To trace the cause of the error, determine what changes have recently been made to the site. This will help to pinpoint the root cause of the issue.

If the error occurred after activating a new plugin or theme, trace that modification first. Try to disable the new feature and check if the page is back on.

If there are no recently added plugins or themes, the error log should state where the problem is. It will lead you to the corrupted file and even the line.

The next step is to follow the path and correct the mistake in the code.

The error message will vary depending on the type of the parse error.

1. A typical Syntax error message:

“Parse error: syntax error, unexpected character in path/to/php-file.php on line number“

2. A typical Unexpected error message:

“Parse error: unexpected character in path/to/php-file.php on line number“

Instead of a character, it may trace a string.

3. A typical Undefined constant error message:

“Notice: Use of undefined constant constant string – assumed ‘constant string‘ in path/to/php-file.php on line number“

Instead of a constant string, the message may refer to unidentified tokens.

The error message itself leads to the corrupted file and part of the code. To fix it, connect to your WordPress site via an FTP (File Transfer Protocol) program.

Modifying the Corrupted File Using FTP

 

The first step is to connect to your WordPress site via FTP. After that, locate the file that contains the error.

Right-click on the file and choose View/Edit.

Next, find the part of the code that was recently added or modified. Determine if it is missing a closing bracket, a semi-colon, or another character, and make the needed change.

If it’s not possible to identify the incorrect code, then delete the latest modification.

Save the changes, close the file and reload your WordPress site. It should be running again.

However, think twice before deciding to delete the corrupted line instead of fixing it. In some cases, it will resolve the problem, but it can also lead to more issues.

File Restore

 

If efforts to fix the issue have been unsuccessful, try to restore the original file from the backup. This should remove all the modifications that caused the parse error.

It’s possible to find the corrupted file by following the error log path. The actual process of restoring it will depend on the tools used.

The restored file should get the site running in its original format.

Backing up all the files related to the look and function of the page is very important. Although the site host usually backs up data, it's good to have a copy downloaded to the computer.

Tracing the Error Through Debugging

Another method for fixing the syntax error is to enable debugging. This process can identify what causes performance issues on a website.

Activating WP-DEBUG is one of the simplest ways to log errors on a WordPress site.

To enable it, go to the wp-config.php file in the WordPress installation. Next, look for the following line:

define(‘WP_DEBUG’, false);

Once located, replace 'false' with 'true'. If there is no such line in the file, add it at the top.

Now, refresh your site. Instead of the previously displayed blank white page, there should be a list of errors.

This way it’s possible to trace the cause of the problem.

If there are no errors listed, it may be due to a wrong debugging configuration on the server. In such a case, talk to the web host.

The error messages displayed as a result of the debugging may show that the issue is caused by a plugin. The message will be similar to the following notification:

Cannot redeclare get_posts()in/var/www/html/wordpress/wp-content/plugins/my-test-plug my-test-plugin.php on line 39

Now, navigate to the corrupted plugin and deactivate it.

Plugin Deactivation

 

Plugins/themes are a common cause of a parse error. Problems often occur after activating a new plugin or after updating it.

To fix a plugin error, it’s necessary to disable it. Most of the time access is only possible by using FTP.

Go to admin, select 'Plugins' and 'Deactivate'. This disables all plugins.

The next step is to activate them again one by one and refresh your site each time. Repeat the process until you find the corrupted plugin.

Ending thoughts on WordPress parse error

A parse/syntax error will disable access to your site and the content won't display. But generally, fixing this type of error is not a difficult task.

It is usually caused by a recent modification on the site. Often it's due to a plugin or a theme.

By deactivating the plugin/theme, you should be able to resolve the issue.

The error message could also indicate a mistake in the code. Most of the time, it’s necessary to track the faulty line and modify it.

However, in some cases, it’s necessary to perform backup file restoration or replace WordPress core files. It’s also possible to use the debugging tool to view the log of all the errors.

In order to prevent syntax errors, always take care when working with the code. Try to avoid typos or missing characters.

If you enjoyed reading this article about WordPress parse error, you should read these as well:

Albert Ślusarczyk
Albert Ślusarczyk
As the co-creator of Be Theme, I am a strong believer in designing with care and patience. I pour my energy, time & knowledge into perfecting the theme for our 195,000+ customers.

Comments are closed.

Free cheat sheets available

Subscribe to download a set of cheat sheets for CSS, JS, and HTML

You'll receive an email with the cheat sheets in an instant.