How to Recover Your WordPress Site After a Code Snippet Crash
Content
It's a common scenario for WordPress users of the Code Snippets plugin: you add a new piece of PHP code, hit "Activate," and suddenly your entire site goes down with a critical error, a blank white screen, or a 500 error. This can be a stressful experience, especially if you can't access your WordPress admin dashboard to fix the problem.
This guide will explain why this happens and walk you through the most effective methods to recover your site and get back to using your snippets.
Why Does This Happen?
The Code Snippets plugin runs your custom PHP code directly. If a snippet contains a syntax error, calls a function that doesn't exist, or conflicts with another plugin or theme, it can cause a fatal PHP error. Because the plugin often loads early in the WordPress process, this error can prevent the rest of the site, including your admin dashboard, from loading.
It's important to understand that simply deleting and reinstalling the plugin will not solve the problem. Your snippets, including the problematic one, are stored in your site's database. When you reinstall the plugin, it reactivates all previously active snippets, causing the crash to happen all over again.
Method 1: Use the Built-in Safe Mode (Recommended)
The Code Snippets team has built a special 'Safe Mode' feature specifically for this situation. When enabled, it prevents all snippets from running, allowing you to access your admin area and deactivate or delete the problematic code.
There are two ways to enable Safe Mode:
Option A: Add a Constant to wp-config.php
- Access your website's files via FTP or your hosting provider's file manager.
- Locate the
wp-config.phpfile in the root directory of your WordPress installation. - Edit the file and add the following line of code just before the line that says
/* That's all, stop editing! Happy blogging. */:define( 'CODE_SNIPPETS_SAFE_MODE', true ); - Save the file and upload it back to your server if necessary.
- Visit your website. You should now be able to log into your WordPress admin dashboard.
- Navigate to Snippets > All Snippets. You should see a notice that Safe Mode is active.
- Deactivate or delete the most recently activated snippet(s).
- Once the problematic code is handled, you can remove the line you added to
wp-config.phpto disable Safe Mode.
Option B: Use a URL Parameter
You can temporarily enable Safe Mode by appending ?snippets-safe-mode=true to your website's login or admin URL. For example:https://yourwebsite.com/wp-login.php?snippets-safe-mode=true
orhttps://yourwebsite.com/wp-admin/?snippets-safe-mode=true
This will grant you access to deactivate the bad snippet. Note that this mode is session-based and may need to be reapplied if you navigate away from the admin area.
Method 2: Manually Deactivate the Snippet via Database (Advanced)
If the Safe Mode method does not work for any reason, you can directly edit the database. This requires comfort with tools like phpMyAdmin.
- Access your website's database through your hosting provider's control panel (e.g., phpMyAdmin).
- Look for a table named
wp_snippets. (The prefixwp_may be different if you changed it during installation). - Browse the table's contents to find the snippet causing the issue. You may need to look for recently modified snippets.
- Find the
activecolumn for the problematic snippet and change its value from1to0. - This will deactivate the snippet. Your site should now load normally with the plugin active.
What to Do If You're Still Stuck
If neither method works, the issue might be more complex. Ensure you placed the Safe Mode constant in the correct location in wp-config.php. In rare cases, a severe error might originate from somewhere other than a snippet. For further community assistance, you can describe your specific error message and the steps you've already tried on independent troubleshooting forums.
By using these methods, you can quickly recover from a crashed site and continue using the powerful Code Snippets plugin without losing your valuable custom code.
Related Support Threads Support
-
snippet crush my site and I can’t install it againhttps://wordpress.org/support/topic/snippet-crush-cant-install-it-again/
-
Site crash – plugin delete – new download – new crashhttps://wordpress.org/support/topic/site-crash-plugin-delete-new-download-new-crash/
-
Plugin not workinghttps://wordpress.org/support/topic/plugin-not-working-963/
-
Error 500https://wordpress.org/support/topic/error-500-259/
-
Reactivation Questionhttps://wordpress.org/support/topic/reactivation-question/
-
Website crash after wrong codehttps://wordpress.org/support/topic/website-crash-after-wrong-code/
-
Site Broke with Fatal errorhttps://wordpress.org/support/topic/site-broke-with-fatal-error/
-
Fatal errorhttps://wordpress.org/support/topic/fatal-error-4125/
-
Where is the plug-in folder?https://wordpress.org/support/topic/where-is-the-plug-in-folder/
-
Safe Mode – no way to get to snippets settingshttps://wordpress.org/support/topic/safe-mode-no-way-to-get-to-snippets-settings/
-
Multisite installation led to the crashhttps://wordpress.org/support/topic/multisite-installation-led-to-the-crash/
-
My website crashed after adding a code in code snippethttps://wordpress.org/support/topic/my-website-crashed-after-adding-a-code-in-code-snippet/
-
every time i enable the plugin website crashhttps://wordpress.org/support/topic/every-time-i-enable-the-plugin-website-crash/
-
Site Crashed and I can’t change the snippets causing it!https://wordpress.org/support/topic/site-crashed-and-i-cant-change-the-snippets-causing-it/
-
Code showing at top of sitehttps://wordpress.org/support/topic/code-showing-at-top-of-site/
-
Site crashed – 502 errorhttps://wordpress.org/support/topic/site-crashed-502-error/
-
snippet causing site dead completelyhttps://wordpress.org/support/topic/snippet-causing-site-dead-completely/
-
My site brokehttps://wordpress.org/support/topic/my-site-broke-3/
-
Snippet Plugin Crashed WP Sitehttps://wordpress.org/support/topic/snippet-plugin-crashed-wp-site/
-
Snippet Crashed Website. Safe Mode Not Workinghttps://wordpress.org/support/topic/snippet-crashed-website-safe-mode-not-working/
-
Site crashedhttps://wordpress.org/support/topic/site-crashed-42/
-
Bad snippet cause site to crashhttps://wordpress.org/support/topic/bad-snippet-cause-site-to-crash/
-
Code crashed sitehttps://wordpress.org/support/topic/code-crashed-site/
-
I just activated a snippet and my site broke! Help!https://wordpress.org/support/topic/i-just-activated-a-snippet-and-my-site-broke-help/
-
After i added a code in snippets my site brokehttps://wordpress.org/support/topic/after-i-added-a-code-in-snippets-my-site-broke/
-
Snippet took site downhttps://wordpress.org/support/topic/snippet-took-site-down/
-
Code in Snippet broke my site, how can I delete it?https://wordpress.org/support/topic/code-in-snippet-broke-my-site-how-can-i-delete-it/
-
Site Broke – Plugin Conflicthttps://wordpress.org/support/topic/site-broke-plugin-conflict/
-
Plugin Crashed Sitehttps://wordpress.org/support/topic/plugin-crashed-site-8/
-
I cannot re-activate the pluginhttps://wordpress.org/support/topic/i-cannot-re-activate-the-plugin/
-
snippet active and site downhttps://wordpress.org/support/topic/snippet-active-and-site-down/
-
Snippet has broken my sitehttps://wordpress.org/support/topic/snippet-has-broken-my-site/
-
False code , not able to reverse, code snippet activation crashes my sitehttps://wordpress.org/support/topic/false-code-not-able-to-reverse-code-snippet-activation-crashes-my-site/
-
Ha um erro critico no seu sitehttps://wordpress.org/support/topic/ha-um-erro-critico-no-seu-site-5/
-
Code Snippets crashes the websitehttps://wordpress.org/support/topic/code-snippets-crashes-the-website/
-
Database connection changed site brokehttps://wordpress.org/support/topic/database-connection-changed-site-broke/
-
Can’t recoverhttps://wordpress.org/support/topic/cant-recover/
-
Critical errorhttps://wordpress.org/support/topic/critical-error-783/
-
Code Snippets crashed my site after update to last versionhttps://wordpress.org/support/topic/code-snippets-crashed-my-site-after-update-to-last-version/
-
Plugin breaks my sitehttps://wordpress.org/support/topic/plugin-breaks-my-site-7/
-
a snippet made the site crashhttps://wordpress.org/support/topic/a-snippet-made-the-site-crash/
-
Need Urgent Help: How to remove a code when the plugin is Deactivatedhttps://wordpress.org/support/topic/need-urgent-help-how-to-remove-a-code-when-the-plugin-is-deactivated/
-
CANNOT EVEN REINSTALL after site breaker snippethttps://wordpress.org/support/topic/cannot-even-reinstall-after-site-breaker-snippet/
-
Site is down, safe mode is not workinghttps://wordpress.org/support/topic/site-is-down-safe-mode-is-not-working/
-
Site Brokehttps://wordpress.org/support/topic/site-broke-5/
-
Code Snippet Give Error when Activate pluginhttps://wordpress.org/support/topic/code-snippet-give-error-when-activate-plugin/
-
Site brokehttps://wordpress.org/support/topic/site-broke-3/
-
WordPress crashhttps://wordpress.org/support/topic/wordpress-crash-7/
-
Can’t activate CS Plugin or Delete ithttps://wordpress.org/support/topic/cant-activate-cs-plugin-or-delete-it/
-
Help! Safe mode not working at allhttps://wordpress.org/support/topic/help-safe-mode-not-working-at-all/