How to Fix a Site Crash Caused by a Code Snippet Error
Content
Experiencing the "white screen of death" or a critical error after adding a new code snippet is a common and stressful situation for WordPress users. This guide will explain why this happens and walk you through the most effective methods to recover your site and prevent future crashes.
Why Does This Happen?
The Code Snippets plugin functions like a modular version of your theme's functions.php file. It executes the PHP code you add. If that code contains a syntax error (like a missing semicolon ; or bracket { }) or a fatal logic error (like calling a class that doesn't exist), it can halt the entire WordPress execution process, resulting in a critical error. This is standard PHP behavior, not necessarily a bug in the plugin itself. The error is often visible in the notification email sent by WordPress, pointing to a file like snippet-ops.php(582) : eval()'d code.
How to Recover Your Site and Fix the Error
Here are the most common and effective solutions, starting with the easiest.
Method 1: Use the Built-in Safe Mode (Easiest Method)
The Code Snippets team includes a Safe Mode feature designed specifically for this scenario. It temporarily deactivates all snippets, allowing you to access your dashboard to fix the problem.
To enable Safe Mode, add the following line to your site's wp-config.php file, just before the line that says /* That's all, stop editing! Happy publishing. */.
define( 'CODE_SNIPPETS_SAFE_MODE', true );
Once added, you should be able to log into your WordPress admin area. Navigate to Snippets > All Snippets, identify the most recently added or modified snippet (the most likely culprit), and deactivate or delete it. After resolving the issue, remove the Safe Mode line from your wp-config.php file to reactivate your other snippets.
Method 2: Manually Rename the Plugin Folder (Via FTP/SFTP or File Manager)
If Safe Mode does not work or you cannot access your wp-config.php file, you can disable the entire plugin manually.
- Access your website's files using an FTP/SFTP client or your hosting provider's File Manager.
- Navigate to the
/wp-content/plugins/directory. - Find the
code-snippetsfolder and rename it to something likecode-snippets-off.
This will deactivate the plugin and all snippets, restoring access to your site. You can then rename the folder back to code-snippets to reactivate it. Note: This will leave all snippets inactive, so you will need to reactivate them one-by-one to find which one caused the crash.
Method 3: Delete the Problematic Snippet via Database (Advanced)
If the previous methods are not an option, you can directly remove the bad snippet from your database. Warning: Always back up your database before making any changes.
- Access your database management tool, usually phpMyAdmin, from your hosting control panel.
- Select your WordPress database.
- Find the
wp_snippetstable (the prefixwp_may be different if you changed it during installation). - Browse the table and look for the most recently added snippet. The code will be in the
codecolumn. - Delete the row containing the problematic snippet.
How to Prevent Future Crashes
- Test on a Staging Site: Always test new snippets on a staging or development site before using them on your live website.
- Use the Code Validator: The Code Snippets editor includes a validator that checks for basic syntax errors before you save a snippet. Pay attention to its warnings.
- Enable Error Reporting: Temporarily enabling
WP_DEBUGin yourwp-config.phpfile can provide more detailed error messages during development, helping you catch issues early.
Conclusion
A site crash caused by a code snippet error is almost always recoverable. The key is to remain calm and systematically work through the solutions, starting with Safe Mode. Remember, these errors are typically caused by the custom code within a snippet, not the plugin itself. By using the built-in Safe Mode and testing snippets carefully, you can safely customize your site without fear of bringing it down.
Related Support Threads Support
-
Broke my sitehttps://wordpress.org/support/topic/broke-my-site-238/
-
SERVER DOWNhttps://wordpress.org/support/topic/server-down-18/
-
Will this cause error 500 if some snippet has an error?https://wordpress.org/support/topic/will-this-cause-error-500-if-some-snippet-has-an-error/
-
Code Snippets broke website. How to find snippets in File Managerhttps://wordpress.org/support/topic/code-snippets-broke-website-how-to-find-snippets-in-file-manager/
-
Alternative Way to Fix WordPress Crash due to Bad Snippet Codehttps://wordpress.org/support/topic/alternative-way-to-fix-wordpress-crash-due-to-bad-snippet-code/
-
3.6.6.1 Broken Sitehttps://wordpress.org/support/topic/3-6-6-1-broken-site/
-
After updating to WP 5.9 Code snippet breaks adminpanelhttps://wordpress.org/support/topic/after-updating-to-wp-5-9-code-snippet-breaks-adminpanel/
-
Should this scale of issue not be noted on the front page of “Code Snippits”?https://wordpress.org/support/topic/should-this-scale-of-issue-not-be-noted-on-the-front-page-of-code-snippits/
-
get http: 500 message when Code Snippet is activatedhttps://wordpress.org/support/topic/get-http-500-message-when-code-snippet-is-activated/
-
website crushhttps://wordpress.org/support/topic/website-crush/
-
Console error: downloadable font: OS/2: Bad sTypoLineGaphttps://wordpress.org/support/topic/console-error-downloadable-font-os-2-bad-stypolinegap/
-
Console Errorhttps://wordpress.org/support/topic/console-error-60/
-
Code Snippets (Pro) causing Errors on WordPress Networkhttps://wordpress.org/support/topic/code-snippets-pro-causing-errors-on-wordpress-network/
-
CANNOT UNINSTALL CODE SNIPPETShttps://wordpress.org/support/topic/cannot-uninstall-code-snippets/
-
critical errorhttps://wordpress.org/support/topic/critical-error-137/
-
Snippet code crashed my sitehttps://wordpress.org/support/topic/snippet-code-crashed-my-site/
-
Add new Snippet loads blank pagehttps://wordpress.org/support/topic/add-new-snippet-loads-blank-page/
-
Code Snippet Errorshttps://wordpress.org/support/topic/code-snippet-errors/
-
Code Snippets Crashes Websitehttps://wordpress.org/support/topic/code-snippets-crashes-website/
-
Codesnippets break the websitehttps://wordpress.org/support/topic/codesnippets-break-the-website/
-
Fatal error: Allowed memory size of xxx bytes exhaustedhttps://wordpress.org/support/topic/fatal-error-allowed-memory-size-of-xxx-bytes-exhausted-4/
-
Error 500 after activating a CSS type snippethttps://wordpress.org/support/topic/error-500-after-activating-a-css-type-snippet/
-
Website Broken – cricital errorhttps://wordpress.org/support/topic/website-broken-cricital-error/
-
Snippet caused fatal error in WP 5.5https://wordpress.org/support/topic/snippet-caused-fatal-error-in-wp-5-5/
-
3.6.6 upgrade breaking all my siteshttps://wordpress.org/support/topic/3-6-6-upgrade-breaking-all-my-sites/
-
Got fatal error notify from WordPress.https://wordpress.org/support/topic/got-fatal-error-notify-from-wordpress/
-
The plugin is busted/https://wordpress.org/support/topic/the-plugin-is-busted/
-
Solution If WP_DEBUG and SAFE MODE didn’t work!https://wordpress.org/support/topic/solution-if-wp_debug-and-safe-mode-didnt-work/
-
With this update of code snippets plugin my WordPress crashed with error 505https://wordpress.org/support/topic/with-this-update-of-code-snippets-plugin-my-wordpress-crashed-with-error-505/