Fixing the 'eval()'d code' Error in Code Snippets: A Complete Troubleshooting Guide
Content
One of the most common and alarming issues users face with the Code Snippets plugin is the dreaded "eval()'d code" error, which often results in a fatal error or a completely crashed WordPress site. This guide will explain why this happens and walk you through the most effective solutions to get your site back online.
What Causes the "eval()'d code" Error?
Contrary to what the error message implies, the problem is almost never a bug in the Code Snippets plugin itself. The error originates from a snippet of custom code that you have created and activated. The plugin uses PHP's eval() function to execute your custom code, and if that code contains a syntax error, references a function that doesn't exist, or conflicts with another plugin, it will cause a fatal error. The error is reported from the plugin's snippet-ops.php file because that is where the execution happens.
Common causes include:
- Syntax Errors: A missing semicolon, bracket, or a typo in your code.
- Missing Dependencies: The snippet calls a function from WooCommerce, Dokan, or another plugin that is not active on the site.
- Redeclaring Functions: The snippet is trying to create a function that already exists elsewhere in your codebase.
- Server Configuration: In rare cases, specific code (like
<script>tags in PHP) can conflict with server-level security settings.
How to Fix It: Step-by-Step Solutions
Solution 1: Enable Safe Mode (If Your Site is Crashed)
If the error has made your site inaccessible, your first step is to use the built-in Safe Mode. This feature allows you to disable the Code Snippets plugin without causing further errors, giving you access to your dashboard.
- Access your site via FTP or your hosting provider's file manager.
- Locate and edit the
wp-config.phpfile in your site's root directory. - Add the following line of code above the line that says
/* That's all, stop editing! Happy publishing. */:define( 'CODE_SNIPPETS_SAFE_MODE', true ); - Save the file and reload your WordPress admin dashboard. The plugin should now be inactive, allowing you to log in.
Solution 2: Identify and Deactivate the Problematic Snippet
Once you have access to your dashboard via Safe Mode, you need to find and fix the snippet causing the issue.
- Navigate to Snippets > All Snippets.
- Look for any snippet that is active but might contain errors. Snippets that recently stopped working often point to a missing plugin dependency.
- Deactivate the most recently edited or activated snippet. If you're unsure, deactivate them one by one, testing your site after each deactivation.
- Once the site is stable, you can edit the deactivated snippet to fix the error. Carefully check for syntax mistakes and ensure any external classes or functions it references are available.
- Remember to remove the Safe Mode constant from your
wp-config.phpfile once you are finished.
Solution 3: Check for Common Code Mistakes
Review your snippet's code for these frequent problems:
- Check for Typos: A simple typo like
fucntioninstead offunctioncan break everything. - Check Dependencies: If your snippet uses
wc_get_product()or a class likeDokan_Seller_Setup_Wizard, ensure the WooCommerce or Dokan plugin is installed and active. - Avoid Function Redeclaration: Always use
if ( ! function_exists( 'function_name' ) ) {to wrap your function declarations to prevent conflicts. - Validate Your Code: Use a local code editor or an online PHP validator to check for syntax errors before activating a snippet.
Solution 4: For Persistent Plugin Issues
In very rare cases, like the one mentioned in Thread 19, an error during plugin update or installation can corrupt its files, leading to a different class of errors.
- Completely uninstall the Code Snippets plugin.
- Download a fresh copy from the WordPress plugin repository.
- Manually upload it via FTP or reinstall it through your dashboard. This ensures all plugin files are intact.
Conclusion
While seeing a "eval()'d code" error can be frightening, it is almost always solvable. The key is to understand that the error is a messenger pointing to a problem in your custom code, not the plugin. By using Safe Mode to regain access and then methodically reviewing your snippets, you can resolve the conflict and get your site running smoothly again.
Related Support Threads Support
-
PHP fatal errorhttps://wordpress.org/support/topic/php-fatal-error-379/
-
PB avec la version 3.6.8 du plugin Codes Snippetshttps://wordpress.org/support/topic/pb-avec-la-version-3-6-8-du-plugin-codes-snippets/
-
Error memory exhaustedhttps://wordpress.org/support/topic/error-memory-exhausted/
-
Could not update snippet. Request failed with status code 510https://wordpress.org/support/topic/could-not-update-snippet-request-failed-with-status-code-510/
-
Fatal Errorhttps://wordpress.org/support/topic/fatal-error-4017/
-
failed to open stream:https://wordpress.org/support/topic/failed-to-open-stream-68/
-
Code snippets is generating a php error on my sitehttps://wordpress.org/support/topic/code-snippets-is-generating-a-php-error-on-my-site/
-
The server encountered an internal errorhttps://wordpress.org/support/topic/the-server-encountered-an-internal-error-2/
-
Php error after adding php codehttps://wordpress.org/support/topic/php-error-after-adding-php-code/
-
Critical error = Uncaught Error: Call to a member function is_type() on nullhttps://wordpress.org/support/topic/critical-error-uncaught-error-call-to-a-member-function-is_type-on-null/
-
Code Snippet plugin fails to render proper path…https://wordpress.org/support/topic/code-snippet-plugin-fails-to-render-proper-path/
-
There has been a critical error on this website.https://wordpress.org/support/topic/there-has-been-a-critical-error-on-this-website-139/
-
Crash on fresh install/activate.https://wordpress.org/support/topic/crash-on-fresh-install-activate/
-
Code broke my affiliate plugin pagehttps://wordpress.org/support/topic/code-broke-my-affiliate-plugin-page/
-
SCRIPT Tags caused connexion resethttps://wordpress.org/support/topic/script-tags-caused-connexion-reset/
-
Code Snippets shows fatal error when trying to insert first snippethttps://wordpress.org/support/topic/code-snippets-shows-fatal-error-when-trying-to-insert-first-snippet/
-
Critical error on updating to the latest version of the puglinhttps://wordpress.org/support/topic/critical-error-on-updating-to-the-latest-version-of-the-puglin/
-
Help Fatal Errore Code snippet Plugin Site Crashhttps://wordpress.org/support/topic/help-fatal-errore-code-snippet-plugin-site-crash/
-
PHP Fatal errorhttps://wordpress.org/support/topic/php-fatal-error-393/
-
Code Snippets Not workinghttps://wordpress.org/support/topic/code-snippets-not-working-2/
-
Critical Error upon activationhttps://wordpress.org/support/topic/critical-error-upon-activation-3/
-
PHP Fatal error: Uncaught TypeError: array_key_exists(): Argument #2 ($array)https://wordpress.org/support/topic/php-fatal-error-uncaught-typeerror-array_key_exists-argument-2-array/
-
most snippets doesn’t work anymorehttps://wordpress.org/support/topic/most-snippets-doesnt-work-anymore/
-
E_COMPILE_ERRORhttps://wordpress.org/support/topic/e_compile_error-6/
-
Error while adding custom snippethttps://wordpress.org/support/topic/error-while-adding-custom-snippet/
-
Code Snippet breaks site error 500https://wordpress.org/support/topic/code-snippet-breaks-site-error-500/
-
Code Snippet has broke my websitehttps://wordpress.org/support/topic/code-snippet-has-broke-my-website/
-
Can’t delete snippet after errorhttps://wordpress.org/support/topic/cant-delete-snippet-after-error/
-
Fatal error – not possible to run in safe mode..https://wordpress.org/support/topic/fatal-error-not-possible-to-run-in-safe-mode/
-
this will a critical error on this websitehttps://wordpress.org/support/topic/this-will-a-critical-error-on-this-website/
-
Fatal error: Uncaught Error: Cannot use object of type WP_Error as array inhttps://wordpress.org/support/topic/fatal-error-uncaught-error-cannot-use-object-of-type-wp_error-as-array-in-2/
-
Code snippet plugin issuehttps://wordpress.org/support/topic/code-snippet-plugin-issue/
-
error message when trying to install and activatehttps://wordpress.org/support/topic/error-message-when-trying-to-install-and-activate/
-
Error code_snippets_editor_attshttps://wordpress.org/support/topic/error-code_snippets_editor_atts/
-
Imported snippets on a new activation and site diedhttps://wordpress.org/support/topic/imported-snippets-on-a-new-activation-and-site-died/
-
Fatal Errorhttps://wordpress.org/support/topic/fatal-error-3493/
-
Fatal Error – snippet-ops.php file – Dokanhttps://wordpress.org/support/topic/fatal-error-snippet-ops-php-file-dokan/
-
Fatal error caused by front end highlightinghttps://wordpress.org/support/topic/fatal-error-caused-by-front-end-highlighting/
-
Code Snippets Plugin fails to installhttps://wordpress.org/support/topic/code-snippets-plugin-fails-to-install/
-
Problem when activate the pluginhttps://wordpress.org/support/topic/problem-when-activate-the-plugin-2/
-
Activating code snippets plugin crashed sitehttps://wordpress.org/support/topic/activating-code-snippets-plugin-crashed-site/
-
Fatal Error report from WordPress for Snippets Pluginhttps://wordpress.org/support/topic/fatal-error-report-from-wordpress-for-snippets-plugin/
-
Error E_PARSE snippet plugin – WordPresshttps://wordpress.org/support/topic/error-e_parse-snippet-plugin-wordpress/
-
Fatal Errorhttps://wordpress.org/support/topic/fatal-error-3738/
-
Code Snippet E_PARSE Errorhttps://wordpress.org/support/topic/code-snippet-e_parse-error/
-
Internal Errorhttps://wordpress.org/support/topic/internal-error-28/
-
Broke my sitehttps://wordpress.org/support/topic/broke-my-site-248/
-
Critical WordPress error when activatinghttps://wordpress.org/support/topic/critical-wordpress-error-when-activating/
-
Unable to install pluginhttps://wordpress.org/support/topic/unable-to-install-plugin-7/
-
Проблема при установке плагина Code Snippetshttps://wordpress.org/support/topic/%d0%bf%d1%80%d0%be%d0%b1%d0%bb%d0%b5%d0%bc%d0%b0-%d0%bf%d1%80%d0%b8-%d1%83%d1%81%d1%82%d0%b0%d0%bd%d0%be%d0%b2%d0%ba%d0%b5-%d0%bf%d0%bb%d0%b0%d0%b3%d0%b8%d0%bd%d0%b0-code-snippets/
-
fatal errorhttps://wordpress.org/support/topic/fatal-error-4152/
-
critical errorhttps://wordpress.org/support/topic/critical-error-303/
-
Parse error at Multisite WPhttps://wordpress.org/support/topic/parse-error-at-multisite-wp/
-
Fatal Error Due to Duplicate Function Declaration in Code Snippets Pluginhttps://wordpress.org/support/topic/fatal-error-due-to-duplicate-function-declaration-in-code-snippets-plugin-2/
-
Code Snippet problem with UberMenu install in GeneratePress.https://wordpress.org/support/topic/code-snippet-problem-with-ubermenu-install-in-generatepress/
-
Issue moving Snippethttps://wordpress.org/support/topic/issue-moving-snipper/
-
Unable to activate Code Snippets pluginhttps://wordpress.org/support/topic/unable-to-activate-code-snippets-plugin/
-
Code Snippets Crashes my sitehttps://wordpress.org/support/topic/code-snippets-crashes-my-site/
-
code 17https://wordpress.org/support/topic/code-17-2/
-
“::class” unsupported?https://wordpress.org/support/topic/class-unsupported/
-
php errorhttps://wordpress.org/support/topic/php-error-538/
-
Plugin Breaks My Sitehttps://wordpress.org/support/topic/plugin-breaks-my-site-8/
-
Code Snippets caused origin errorhttps://wordpress.org/support/topic/code-snippets-caused-origin-error/
-
PHP Fatal Error: Uncaught Errorhttps://wordpress.org/support/topic/php-fatal-error-uncaught-error-21/
-
Fatal Error even after complete uninstallhttps://wordpress.org/support/topic/fatal-error-even-after-complete-uninstall/
-
jQuery functionhttps://wordpress.org/support/topic/jquery-funtion/
-
E_PARSE error?https://wordpress.org/support/topic/e_parse-error-2/
-
Uncaught Error: Call to undefined functionhttps://wordpress.org/support/topic/uncaught-error-call-to-undefined-function-10/
-
“The plugin does not have a valid header.”https://wordpress.org/support/topic/the-plugin-does-not-have-a-valid-header-231/
-
Code snippets just broke my sitehttps://wordpress.org/support/topic/code-snippets-just-broke-my-site/
-
Uncaught errorhttps://wordpress.org/support/topic/uncaught-error-11/
-
Critical Error on Exporting Snippetshttps://wordpress.org/support/topic/critical-error-on-exporting-snippets/
-
Code Snippet error (582)https://wordpress.org/support/topic/urgent-code-snippet-error-582/
-
Fatal Crashhttps://wordpress.org/support/topic/fatal-crash-2/
-
using url in codehttps://wordpress.org/support/topic/using-url-in-code/
-
PHP Snippets errorhttps://wordpress.org/support/topic/php-snippets-error-2/
-
My Website totally crushed with Code Snippetshttps://wordpress.org/support/topic/my-website-totally-crushed-with-code-snippets/
-
code snippets fatal error breaking xml sitemapshttps://wordpress.org/support/topic/code-snippets-fatal-error-breaking-xml-sitemaps/
-
Not able to do a simple SELECT from a table with Code Snippetshttps://wordpress.org/support/topic/not-able-to-do-a-simple-select-from-a-table-with-code-snippets/
-
Activation of the plugin broke the backend of my webhttps://wordpress.org/support/topic/activation-of-the-plugin-broke-the-backend-of-my-web/
-
Code Snippets Fatal Errorhttps://wordpress.org/support/topic/code-snippets-fatal-error/
-
E_PARSE errorhttps://wordpress.org/support/topic/e_parse-error-6/
-
An error of type E_PARSE was caused in line 122https://wordpress.org/support/topic/an-error-of-type-e_parse-was-caused-in-line-122/