The short answer
Take out exactly the code you added and the site comes back. If you can’t get into WordPress, open your theme’s functions.php in your host’s file manager, remove the block you pasted and save. The code usually wasn’t nonsense: it was written for a typical WordPress site, and something about yours is different.
Asking ChatGPT, Claude or another assistant for a snippet of PHP is a sensible thing to try. The assistant can’t see your site, though. It writes code for the WordPress site it imagines from your question, and it has to guess which theme you use, whether you have a child theme, which plugins are active and which PHP version your server runs. When one of those guesses is wrong, a single pasted block can stop the whole site with a critical error or a blank page.
The good news is that you know exactly what changed, and the code is probably still sitting in the chat. That makes this one of the quicker problems to undo.
Is this what you’re seeing?
- ChatGPT gave you PHP code for
functions.php, you pasted it in, and the website crashed as soon as you saved. - The site now shows “There has been a critical error on this website”, or just a white page.
- wp-admin is broken too, so you can’t log in to take the code out again.
- The theme file editor wouldn’t save the change, or said something went wrong and you may need to fix the file another way.
- A plugin an AI assistant wrote for you stops the site loading, or breaks one feature.
- Custom code you added in Elementor has broken a menu, a form or a whole page.
- You’ve made several AI-suggested changes over time and want someone to undo them, but you’re not sure what was changed.
What usually causes it
A slip when copying and pasting
PHP is strict. One missing bracket or semicolon stops the whole file from running, and functions.php runs on every page. Common slips are pasting a second <?php opening tag into a file that already has one, copying only part of the answer, or pasting through a word processor that turns straight quotes into curly ones. How to tell: the error says “syntax error, unexpected …” and names functions.php with a line number close to where you pasted.
The code expects something your site doesn’t have
This is the “reasonable assumption” problem. The code calls a WooCommerce or Advanced Custom Fields function on a site that doesn’t run that plugin, hooks into a feature of a different theme, or uses PHP that your server’s version doesn’t support. The code may be fine in itself. It just wasn’t written for your site. How to tell: the error says “Call to undefined function” or “Class … not found”, naming something that came from the snippet.
A function with that name already exists
If the first attempt didn’t seem to work and you pasted a corrected version underneath, the same function is now there twice. The theme or a plugin may also already use that name. How to tell: the error says “Cannot redeclare” followed by the function’s name.
It went into the wrong file, or the wrong place in the file
Many sites run a child theme on top of a parent theme, and the code belongs in the child. Code pasted in the middle of another function, or after a closing ?> tag, can break things in odd ways. Code in a parent theme’s functions.php also disappears next time the theme updates, which can look like a second, separate problem. How to tell: the error names a line inside code you didn’t write, or a change that worked has vanished after an update.
It runs, but does more than you meant
Some code doesn’t crash anything. It redirects pages in a loop, hides part of the admin, slows every page or, with JavaScript added in Elementor, stops a menu or popup working. How to tell: the site loads but something changed at the moment you added the code. For JavaScript, the browser’s console (press F12) shows red errors when the page loads.
What you can safely try
Take a backup first. If you can’t log in to WordPress, use your host’s control panel backup, and download a copy of functions.php to your computer before you change it.
- Find the error message. Check the site admin email for “Your Site is Experiencing a Technical Issue”, or turn on the debug log as described in the critical error guide. Note the file name and line number.
- In your host’s file manager (or by FTP), open
wp-content/themes/and find the active theme’s folder. If there’s also a folder whose name ends in-child, the site probably uses a child theme, so check itsfunctions.phpas well as the parent’s. - Open
functions.php, find the block you pasted by comparing it with the chat, and delete that block and nothing else. Save, then check the site in a private browser window. If it’s still broken, put your downloaded copy back and look again at the error. - If you can’t tell which lines you added, restore just
functions.phpfrom a backup taken before the change. Most control panels let you restore a single file. That doesn’t touch the database, so orders and enquiries since then are safe. - If you added the code through a snippets plugin, use its safe mode. For Code Snippets, add
define( 'CODE_SNIPPETS_SAFE_MODE', true );towp-config.php, log in, switch off the snippet, then remove the line. WPCode has its own safe mode, explained in its documentation. - If it’s a plugin the AI wrote, rename its folder in
wp-content/plugins/, for example frommy-custom-plugintomy-custom-plugin-off. WordPress treats it as switched off. Rename it back to undo. - If it’s Elementor code, open the page in Elementor and remove or edit the HTML widget you added. Code added in Elementor Pro’s Custom Code section can be unpublished from there.
- When the site is back, switch off the debug log and delete
debug.log.
When to stop and get help
- The error still appears after the code is out, or now names a file you didn’t touch.
- The code changed data, for example by updating products, deleting posts or changing user roles. Removing the code doesn’t undo what it already did.
- It touched the checkout, payments, logins or member accounts.
- You’re not sure which theme is active, or which copy of
functions.phpyou edited. - An AI tool had direct access to the site and you don’t know everything it changed.
- You still need what the code was meant to do, and want it done in a way that won’t break again.
A real example
The pattern I see most often isn’t bad code. It’s sound code written for a different site. It calls a function from a plugin the site doesn’t use, or it goes into the parent theme when the site runs a child theme, or it’s pasted a second time after the first try seemed not to work, so the same function is declared twice. Taking it out is quick. The more useful part comes after: working out what the code was meant to do, checking how the site is really built, and then adding a version that fits. Usually that goes in a child theme or a snippets plugin, where a theme update won’t wipe it and one bad line can be switched off without a trip to the file manager.
It’s the same reason AI instructions sometimes don’t fix a problem: they rest on a guess about the site’s set-up. I’ve written more about that in why ChatGPT’s WordPress instructions didn’t fix your site, and about finding out what your site is made of in how to work out how your WordPress site was built.
Getting it fixed
Send me the code you added, where you put it and the error you’re seeing. I take a full backup, remove it cleanly, check nothing else was changed, and if you still want what it was for, add a version that suits your site. A WordPress repair is a fixed £119, which covers finding the problem and up to 90 minutes of fixing it. Most repairs fit in that, and you’re never charged more without agreeing first.
If your site is down and it’s costing you money right now, see emergency WordPress support for a faster start.
Questions
Can someone undo code changes made by an AI assistant?
Yes. It helps a lot if you still have the conversation, because it shows exactly what was added and where. If the changes were made over several sessions, or by a tool with direct access to the site, I compare the site’s files against clean copies of the theme and plugins to find everything that was changed.
How do I safely remove AI-generated code from my WordPress site?
First list every place it might be: the parent and child theme’s functions.php, a snippets plugin, any custom plugin, Elementor HTML widgets and Custom Code, the Additional CSS box and any “header and footer scripts” plugin. Then remove one piece at a time and check the site after each, so you know which piece did what.
Can you fix an AI-generated WordPress plugin?
Usually. I check that it works with your theme, plugins and PHP version, and that it’s safe: that only the right people can trigger it and that anything typed into it is cleaned before use. Sometimes a well-maintained plugin already does the same job, and switching to it is the better answer.
My AI-generated Elementor custom code is causing errors. What now?
JavaScript or HTML added in Elementor rarely takes the whole site down, but it can stop menus, popups, sliders or forms working. Unpublish or remove the code, use Elementor’s option to regenerate its CSS, clear your caching plugin, and check the page again. If the Elementor editor itself won’t open, see when the Elementor editor won’t load.
Why did WordPress let me save code that broke the site?
The theme file editor in wp-admin does try to catch code that would crash the site and refuse to save it, but it doesn’t catch everything. Code saved through your host’s file manager or by FTP isn’t checked at all.
Should I stop using AI for WordPress code?
Not necessarily. Give it more to go on: your theme and whether it’s a child theme, the main plugins, your PHP version and the exact error message. Add the code through a snippets plugin with a safe mode, test it on a staging copy if your host offers one, and keep a backup. That way a wrong guess costs you a minute, not a morning.
Written by Peter Claridge, who fixes WordPress sites for businesses across the UK from Reading. Last checked on WordPress 7.1, November 2026.