Fixing Syntax Error in Theme File

Parse Error: syntax error ↑ Back to top

You have added (most probably while using the Theme Editor) invalid code to a .php file, which will produce a parse error. When you try to access your website or the admin area, you get a blank page or an info about the error.

Necessary tools ↑ Back to top

First of all, you will need an FTP client like  Transmit (Mac), Cyberduck (FREE – Mac/Win), FileZilla (FREE – Win) or FireFTP (FREE – Firefox Addon). In this example, Transmit is used.

You will also need a text/code editor. It could be even Notepad or TextEdit, but we recommend software dedicated for code editing:  Coda (Mac), TextMate (Mac), Sublime Text 2 (Mac/Win/Lin), TextWrangler (FREE – Mac) or Notepad++ (FREE – Win), Atom (FREE – Mac). For the purpose of this tutorial, Sublime Text 2 was used.

How to fix it? ↑ Back to top

1. Connect to your server, using the FTP client of your choice (if you don’t know what your credentials are, you should contact your web host, and they should fix you up with that):

transmit

2. When you establish a connection with the server, you should be able to see the WordPress files (if not, you will have to look in one of the subfolders in the main directory):

transmit2

3. Navigate to /wp-content/themes/name-of-your-theme and locate the file which has been corrupted. In this tutorial it’s the functions.php file.

4. Go ahead and download the corrupted file to your computer.

transmit-functions

5. The PHP error might help you because it points to the exact code line where the code is invalid.

phperror

Open the corrupted file, in the code editor of your choice, and remove the invalid code. Remember to save the changes afterwards.

functions-file

6. Go back to the FTP client, and replace the corrupted file on the server, with the saved file.

replace-functions

Assuming you have followed all the steps correctly, your site should be up and running again!

Please keep in mind, that the appearance will vary, based on the chosen software. For more info on WordPress and FTP, check out this article.

WooCommerce - the most customizable eCommerce platform for building your online business.

Back to the top