Tutorial, Ubuntu, Woo Commerce

Code Snippets Busted Broke Crashed Killed My Website

Now this was a bit of a heart-attack time for me so I thought I’d do a quick blog to clarify a few things so that the victim (like me) can more calmly walk through the situation. First, let’s make sure you are in the same situation as me.

Checking Situation

I had code snippets installed on my Woo commerce wordpress site and it was working pretty great and doing cool things.

I stuck a snippet I found online in there and clicked save. I noticed the function that should have been working wasn’t. Possibly this is because the plugin knew that my code was bad and wouldn’t allow it to activate

I went into Code Snippets plugin and realized it was not activated.

I manually clicked ‘activate’ and boom. My front end and backend went down right away with this message:


There has been a critical error on this website.

Learn more about troubleshooting wordpress.


So, the last snippet I saved was the problem for sure.

Thankfully I landed on a forum post page with a thoughtful at great solution here however, the solution wasn’t perfectly clear if you haven’t been through this before so I’d like to take the solution and dumb it down a few levels.

The Fix

If you’re still logged in via browser (the event just happened), then you might be in luck for the easy fix as per the blog, by simply putting the plugin into ‘safe mode’ with a handy-dandy URL:

https://example.com/wp-admin/admin.php?page=snippets&snippets-safe-mode=true

So, in the same browser that you just crashed while using the backend of your wordpress admin, paste the above code in replacing example.com with your website.

If you’re lucky your site will be back up with Code Snippets working as well and you can just assure your fail snippet is deactivated and all should be good.

If you can’t login or somehow got logged out, then you’ll need to:

Force a safe mode for Code Snippets in your wp-config.php file

If you are using CLI / terminal like me:

  1. find your wordpress install (often at var/www/html)
  2. in the main directory you should see the wp-config.php file
  3. in ubuntu nano wp-config.php
  4. use your page down button and get to bottom of the text in the file
  5. paste in this code block (I added the comment so you can copy that too and remember what it is later:
/** Force Code Snippets plugin into safe mode. */
define('CODE_SNIPPETS_SAFE_MODE', true);
  1. Control x to save and y to save changes and enter to execute

Hopefully now you can get back into your admin page after refreshing

Once you’ve deactivated everything you ‘should’ be able to reverse the steps above and delete the forced safe mode code again and save the file

Other Comments

If you are using cpanel or something like that, you’d have to adjust my instructions above to find that file and edit it. It has been too long since I’ve used so I can’t comment.

If the above didn’t work, you can also get into the database itself and wipe out the failed snippet. This would require you to use phpmyadmin or mysql command lines. Thanks again to that Keniry poster in the forum post above for this comment:

The snippet should be in wp_snippets – The offending snippet/s can be deactivated with a value of 0.

All the best!

Tagged , , , , , ,

Leave a Reply

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