How to Fix a Syntax Error After You’ve Broken Your WordPress Site with the Appearance Editor

While writing a Quick Guide on a different topic, I had the idea that maybe just this once it would be OK to edit my code in the Appearance editor (at “Appearance > Editor” on most WordPress sites.). I should know better after reading all about how this isn’t a good idea, but what can I say, sometimes you just have to learn hard lessons yourself. If you’re curious, here’s where I made my silly mistake:

how to fix a syntax error in WordPress

(click to enlarge)

Unsurprisingly, I found myself with a broken site. In this situation, not only would it not load for visitors, but I also wasn’t able to access the WordPress dashboard to go back to the appearance editor and delete my bad code! (This is, if you didn’t follow the link, the basic reason you shouldn’t use the Appearance editor.)

how to fix a syntax error in WordPress

(click to enlarge)

If you find yourself in a similar situation after breaking your site with the Appearance editor, here’s how to fix it:

  1. Make sure you have three things set up on your computer: a usable file structure, a text editor, and an FTP client. If you don’t have these yet, check out Three Things You Need Before Making Changes to Your CSS. I use a program called Coda that serves as both my FTP client and text editor.
  2. Use your FTP client to locate the server-side file you made changes to in your appearance editor. In this case, I went to: public_html/wp-content/rosemary-child/functions.php. rosemary-child is my child theme folder, you’re is probably different. You’ll also want to make sure you’re editing the file that’s on the server, rather than its counterpart on your desktop. In Coda, you can tell if you’re doing this because “Remote” will be in blue at the bottom of the window.

    how to fix a syntax error in WordPress

    (click to enlarge)

  3. Open this file, and find the code you recently added that is causing the syntax error. The error message on your currently broken site will also point you to the specific line that’s causing the problem. One poorly placed semicolon is all it takes to create this type of problem. If you don’t know what specific issue you introduced, check out these recommendations of what to look for.

    how to fix a syntax error in WordPress

    (click to enlarge)

  4. Once you’ve fixed the code in question, save your changes. If you’re using Coda, you’ll get an alert when your upload is complete, and your server has received and incorporated your changes.

    how to fix a syntax error in WordPress

    (click to enlarge)

  5. Reload your site in your web browser. Whew! If you fixed the syntax problem properly, the error message will be replaced by the page in the appearance editor when you originally made your mistake. Now that you’ve fixed it, step away from the Appearance editor. Make any further edits edits in your text editor instead!

    how to fix a syntax error in WordPress

    (click to enlarge)


1 Response

Pingbacks

Add a Comment

Your email address will not be published. Required fields are marked *