Parse Error: Syntax Error Unexpected ‘ ‘ in WordPress
Table of Contents [TOC]
Trying something new on your WordPress site? Got any of the following errors like
⚠️ parse error: syntax error, unexpected t_string wordpress,
⚠️ parse error syntax error unexpected end of file in wordpress,
⚠️ parse error: syntax error, unexpected t_function wordpress,
⚠️ parse error syntax error unexpected text t_string wordpress,
⚠️ parse error syntax error unexpected if t_if wordpress,
⚠️ wordpress parse error syntax error unexpected expecting or ‘;’
then don’t freak out. You are not the first one to receive the parse error in WordPress. In this article we will show you how to fix the unexpected syntax error in WordPress. The parse error in WordPress isn’t a common error, and it typically occurs through a mistake made by the user.
Sometimes we install a new plugin in our WordPress and when we activate it we get a syntax error. Sometimes that error appears between the content, but sometimes all the content disappears and we only see the error. Or worse, sometimes not even that. We only have a blank screen.
We are here to tell you that this is completely normal if you have seen the “Syntax Error”⚠️ message because WordPress can sometimes be confusing with annoying syntax errors.
These errors occur if the correct PHP syntax rules are not followed. In this tutorial, we will show you how to fix syntax error in WordPress with simple instructions for beginners.
Let’s see how to understand, debug and fix a syntax error, or alternatively, at least isolate it:
Some Commonly Asked Questions:
- How to Fix the Syntax Error in WordPress?
- How to Fix Parse error: syntax error, unexpected ‘ ‘ WordPress?⚠️
- How to Fix the Parse Error in WordPress?
- How to debug and fix WordPress Syntax Errors?
In this post you will also know more about:
- How do you fix a syntax error?
- What is parse error syntax error unexpected?
- What is a parse error in WordPress?
- How do I fix invalid syntax in Python?
- What causes a syntax error?
- What Is syntax error with example?
What are parse error: syntax errors ?
PHP errors⚠️ can occur when your code is being converted from a series of characters to something that is visible to the visitors of your site.
This error may also happen when an update is made by the developer of a theme or an extension (this is rather rare, but it can happen).
For example, you may have made syntax errors in your code by forgetting parentheses, adding spaces or characters.
These errors occur when the PHP code can’t start or finish being parsed. Obviously, if this is the case, something terribly wrong has happened and it may take more than putting some } there to heal your code.
This could be a copy and paste problem. Maybe the developer did not copy and paste the lines of the code as mentioned in the tutorial.
⚠️ The most probable cause of the error is a missing or a mismatched parenthesis in the PHP code
In WordPress, there are typically 3 main kinds of parse error which may occur to your WordPress site:
⚠️ Syntax error – It occurs because of the semicolons, curly brackets or quotations that were used in the PHP code. Either one of them is missing or the wrong ones were added.
⚠️ Unexpected error – It happens when you include a character such as an opening or closing bracket or other similar characters. This is a parse error which occurs when php is still looking for something and reaches the end of the file without finding it. It could be a quote or bracket which is unclosed, and php is still treating the file contents as a part of the quote.
Php is just telling you it was unexpected
⚠️ Undefined constant error – This is the problem with the character missing in an array while referencing a variable or possible scenarios.
It is extremely important to keep in mind that these three kinds of parsing errors have many different variations depending on the specific mistake in the written PHP code.
Related Issue – Fix WordPress Stuck in Maintenance Mode
What Is A Syntax Error?
The WordPress syntax error is common among users who add code snippets to their WordPress sites. When this error occurs, you usually see something like in the homepage of the website:
⚠️ Parse error: syntax error, unexpected T_FUNCTION in /home/content/94/4245094/html/wp-content/plugins/my-calendar/my-calendar-styles.php on line 465
Often this error happens because a programming language is not used properly, that is, the rules are not followed and the code is written incorrectly. It can be something as simple as not placing a semicolon, or that a complete file is misspelled. When compiling, it will not be understood and that error will appear. The positive thing about this error is that you will know exactly what it is and we will see how to correct it. In case you run a multi wordpress site and want to find out which user activity lead to this error, it can be found by monitoring user activity in wordpress dashboard.
Syntax errors structure:
“Parse error: syntax error, unexpected
character
in path/to/php-file.php on linenumber
“
Undefined constant errors structure:
“Notice: Use of undefined constant
constant string
– assumed ‘constant string
‘ in path/to/php-file.php on linenumber
“
Unexpected errors Example
“Parse error: unexpected
character
in path/to/php-file.php on linenumber
“
Unexpected parse errors may list a string instead of a character.
In each of these examples, number
refers to the line number and is going to be replaced with actual numbers such as 23 or 1256, for example, though, not necessarily those exact line numbers.
- The file indicated in the error message is – where the issue persists
- The line number gives you a hint as to where to look for the mistake.
The character
or constant string
names give you an idea of what to look for around the indicated line number. These are what needs fixing or else they’re related to what needs correcting.
Related Read – Fix Sorry, This File Type Is Not Permitted For Security Reasons
What Causes the PHP parse/syntax errors in WordPress?
Even a small typo error in the wrong place can cause the operation of your entire WordPress page to stop working. However, the message “Syntax error” is not an insoluble problem.
A syntax error is, as a rule, caused by a small critical error in the syntax of your code. A missing comma or an incorrect parenthesis interrupts the entire script. Have you recently installed a snippet or updated a plugin? If this is the case, then you should check this first.
To resolve WordPress syntax errors, you must rework the part of the code that caused this error. Either you delete it completely or you correct the syntax.
As a beginner, it is not uncommon to be quickly frustrated when a single mistake makes the entire site inaccessible. If you have added the code in your WordPress dashboard via the editor area then it is no longer possible to directly access your WordPress code.
How to detect syntax error in wordpress?
If the error appeared just after you have pasted some block of code, check the latter mainly.
Anyway, in the syntax error message, you will see the damaged file and the line of code that you should review. This is also seen when you activate the debug by defining define (‘WP_DEBUG’, true); in wp-config.php.
- Check that you do not miss any semicolons. There are codes that at first glance do not seem to have an error, and adding a semicolon at the end, the error message disappears.
- Check that the quotes are in the proper format, in PHP the double and single quotes are used, make sure they are not italic.
- Check that there is no missing parenthesis to open or close. You can PHP code syntax for any errors using this handy tool.
To identify the origin or cause of this error, follow the steps below:
- wp-config.php: Activate debug by defining define (‘WP_DEBUG’, true); Normally it will throw the error on the screen where it will indicate the file, the line and the type of error that was found during the execution.
- Close each order: Check that you do not lack a ; at the close of each line.
- Check the quotes: In PHP, single quotes and double quotes are used. Sometimes, when copying and pasting, the format is moved and the quotes appear cursive (curly quotes). Example: “” instead of “” or ‘’ instead of ”.
- Check the parentheses: It is very common in instructions with leaving a parenthesis to close or to open. Balanced parentheses require every opening parenthesis to be closed in the reverse order opened.
How To Find Parse Error in WordPress?
The easiest way to open a PHP file is to open it using the default text editor on your computer. The default text editor is based on JavaScript which allows it to run on several platforms and CMS like WordPress and is compatible with most web browsers.
The text editors allow us to write while we see the final result of the text.
And ultimately, the editor generates the content as text, images and other elements in HTML code and shows it to us in a similar way to how it will be on our website.
Popular text editors include
Related Read – How To Fix “This Account Has Been Suspended” error in WordPress
How To Fix parse error syntax error unexpected ‘ ‘ in wordpress Via FTP?
In order to fix the Syntax Error in WordPress you need to edit the code that caused this error. The only possible way to resolve the syntax error is to directly exchange the faulty code via FTP or access the file you last edited using FTP.
Steps to Fix Syntax Error in WordPress Via FTP
- >> After installing the FTP program
- >> connect it to your website
- >> go to the theme file that needs editing.
In case you forgot which file you need to edit, just look at the error code. The error will tell you exactly which file and which line you need to edit.
- >> Remove the code you last added / write the code in correct syntax
- >> Save the file and upload it back to your server
- >> Come to your WordPress site and refresh the page, and it will open as before..
Fix Parse Error by Uploading Fresh Files
- If you cannot figure out how to fix your code >> try uploading a fresh version of the file.
- If your theme is the problem >> download a copy of it (the version you’re using).
- If you only have the original folder archived and have only updated the theme through the WordPress admin ever since >> download a fresh copy of it from your theme provider.
- If you do choose the WordPress root and your problem is with wp-includes or wp-admin >> you can safely upload fresh copies of these files to your site.
Tools To Help You Fix The Syntax Error in WordPress
If you have already tried the above steps and still get the syntax error, we recommend that you should try the tools given below:
PHP Storm
It is an IDE considered quite complete with its paid version of monthly or annual membership (USD $199) you can receive all the updates. Php Storm is part of JetBrains, and they offer the whole package (including PHPStorm) for USD 649 per year.
However, they offer a version for university students, with the prohibition of use for commercial purposes.
Visual Studio Code
It is a code editor with many features for beginners and experts. Visual Studio Code also accepts multiple extensions and customizations.
Related Read – How To Fix WordPress Not Sending Email Issue
How To Avoid Syntax Errors?
The ideal is that you learn PHP because knowledge of a language is what helps you to detect errors in your code at a glance.
Avoiding these errors is as easy as fixing them if you’re at least a little familiar with PHP. You can check your code for syntax mistakes automatically by running it through a PHP code validator.
Otherwise, you can always check your codes before applying them to a website or convert them into a plugin. Here are some tools that can help you:
Here are some tips of the most common syntax mistakes to look out for right off the bat:
- Make sure there’s only one opening (
<?php
) and closing tag (?>
)per document - Add code shouldn’t be inserted in between a function
- Check for functions that are broken up by other ones
Enable debugging
If you still have the error of the syntax error or the admin area does not work (or you have found the cause but you still want to dig more), you can enable debugging which will show you all the errors.
The problem is that when a fatal error occurs, the script stops executing. If this happens before any content is displayed, you will only see an empty white screen.
To enable debugging, you will need to open the wp-config.php file from your WordPress installation. Find the following line:
define(‘WP_DEBUG’, false);
Replace false with true and reload your site. If this line does not exist, add it at the top.
Instead of the blank page, you will now have a blank page with error messages. It’s not much, but now you can start. If you have not disabled plugins and themes yet, you will be able to determine the source of the problem by viewing the error message.
It should indicate the file in which the error occurred. It could be something like this:
Cannot redeclare get_posts()in/var/www/html/wordpress/wp-content/plugins/my-test-plug my-test-plugin.php on line 38
At the end of the message, you can see that the problem is in line 38, and it’s a plugin called “my-test-plugin”. By disabling this plugin, the site should work.
You can correct this line if you like to change the codes. If it is a plugin from the repository, it would be better to write to the author instead of doing it yourself. By modifying the plugin, you will have to maintain all your modifications, which is a puzzle. It is best to wait for the developer to do it.
If you do not see any error after enabling debugging, try contacting your web host because it may be that debugging is not properly configured on your server.
Disable plugins and themes
Check if the error started when you activated a new theme or plugin, so you should replace it or contact the developer. Often this error does not allow you to log into WordPress, so you must use FTP to remove the plugin or theme.
Disabling all your plugins is one of the easiest and most common ways to solve the wordpress syntax error. A bad update of a plugin is often the cause. If you still have access to your admin area, you can quickly get there by going to “Plugins” to select “Deactivate” from the action menu.
This will disable all your plugins. If that solves the problem, all you have to do is find out which plugin is the culprit. Start activating them one by one while loading the site after each activation.
We hope this article helped you fix parse error syntax error wordpress. Now you know how to fix parse errors, what causes them, and how to avoid them in the future.
Read More About Other Common WordPress Errors:
- How to Fix Error Establishing a Database Connection in WordPress?
- Remove “This Site May Be Hacked” From WordPress in Google
- How to fix “The link you followed has expired” in WordPress?
- How to Fix Pluggable.php File Errors in WordPress?
- How To Fix WordPress Upload Failed To Write File To Disk Error?
- WordPress HTTP Image Upload Error – How To Fix It?