🎉 Free WordPress fix for our first 50 sites — in exchange for an honest review. Claim a spot →

Guides

Theme File Edits That Vanish on Update (And What to Do Instead)

Jul 19, 2026 · 7 min read · By the Mend engineering team

When you edit a theme file directly — through the WordPress theme editor or via FTP — your changes are overwritten the next time that theme updates. Beyond lost work, direct edits can break your site instantly, leave no record of what changed, and create security exposure that's hard to close. The right approach is to use a child theme, custom CSS, or a site-specific plugin, depending on what you're trying to change.

What "Editing Theme Files Directly" Actually Means

WordPress ships with a built-in code editor at Appearance → Theme File Editor (previously called Theme Editor). It lets you open any PHP, CSS, or JavaScript file that belongs to your active theme and save changes immediately. You can do the same thing over FTP or SFTP — pulling down a file like functions.php, editing it in a local text editor, and pushing it back up.

Both routes write directly to the theme's own files. That's the problem.

What Goes Wrong — and When

Your changes disappear on every update

Theme developers release updates to patch security vulnerabilities, fix bugs, and add features. When WordPress applies that update, it replaces the theme folder with a fresh copy from the developer. Every line you added to functions.php, every tweak you made to header.php, every custom CSS rule dropped into style.css — gone. Completely. With no warning.

This isn't a WordPress bug. It's working exactly as designed. Updates are meant to be clean replacements. Your edits were never supposed to live there.

One typo can take down the whole site

PHP is unforgiving. A missing semicolon, an unclosed bracket, or a stray character in functions.php triggers a fatal error the moment the file is loaded — which is on every single page request. The result is usually a white screen of death or a "There has been a critical error" message that locks out everyone, including you. The built-in theme editor has no syntax checking before it saves, so it will happily save a broken file without complaint.

There's no version history or undo

WordPress doesn't keep a changelog of theme file edits. If you save a change and something breaks, you're left trying to remember what you changed. If the person who edited the file has left the organization, that knowledge goes with them.

Security exposure from leaving the editor open

WordPress's own recommendations advise disabling the theme and plugin file editors on production sites. Leaving them active means any attacker who gains admin access can immediately inject malicious PHP into your theme — no FTP credentials needed. Many hardening guides recommend adding define( 'DISALLOW_FILE_EDIT', true ); to wp-config.php for exactly this reason.

The Right Alternatives — Matched to What You're Trying to Do

For CSS changes: use the Customizer's Additional CSS panel

Go to Appearance → Customize → Additional CSS. Anything you write here is stored in the database, not in theme files, so it survives updates completely. It's the right place for visual tweaks — colors, fonts, spacing, hiding elements. Changes are previewed live before you publish them, which is a significant safety improvement over editing a file blind.

The limitation: it's CSS only. You can't add PHP logic or JavaScript here.

For PHP logic: use a child theme

A child theme is a small, separate theme that inherits everything from the parent (your main theme) but keeps your customizations in its own folder. When the parent theme updates, the child theme folder is untouched.

Creating one manually takes about five minutes:

  1. Create a new folder in /wp-content/themes/ named something like yourtheme-child.
  2. Inside it, create a style.css with a header that declares the parent theme: Template: yourtheme (use the exact folder name of the parent).
  3. Create a functions.php that starts with <?php — this is where your custom PHP goes.
  4. Activate the child theme at Appearance → Themes.

If you need to modify a specific template file (say, single.php), copy it from the parent theme into the child theme folder and edit the copy there. WordPress loads the child's version first, so your changes take effect — and updates to the parent won't overwrite the child.

One important note: if the parent theme update changes single.php significantly (new hooks, restructured markup), your child theme copy won't get those changes automatically. You'll need to review and merge them manually. That's a manageable trade-off, and far better than losing your work entirely.

For site-wide functionality: use a site-specific plugin

Any code that isn't specifically about presentation — custom post type registration, shortcodes, modified query logic, third-party API integrations — doesn't belong in a theme at all. Theme files are for display. If you switch themes later, you'd lose all that logic.

The solution is a site-specific plugin: a simple plugin you write yourself that exists only on your site and holds your custom PHP. It takes about three lines to register as a plugin:

<?php
/**
 * Plugin Name: My Site Custom Code
 * Description: Site-specific functionality.
 * Version: 1.0
 */

Drop that in a file inside a new folder in /wp-content/plugins/, activate it, and add your functions below. This code survives any theme change, any theme update, and is completely isolated from everything else. It also makes auditing straightforward — everything custom is in one place.

For JavaScript: enqueue it properly

Adding JavaScript by hardcoding a <script> tag into header.php is one of the most common direct-edit mistakes. The right method is to enqueue scripts using wp_enqueue_script() in your child theme's functions.php or site-specific plugin. This gives WordPress control over load order, dependency management, and de-duplication — and keeps your markup out of a file that will be overwritten.

What to Do If You've Already Made Direct Edits

If you've been editing theme files directly, don't panic — but act before the next update wipes everything.

  1. Back up first. Download a full copy of your theme folder right now, before you do anything else.
  2. Open the theme files you've edited and copy out your customizations.
  3. Set up a child theme as described above.
  4. Move CSS changes to the Customizer's Additional CSS panel.
  5. Move PHP changes into the child theme's functions.php or a site-specific plugin.
  6. Move any modified template files (like single.php) into the child theme folder.
  7. Test thoroughly — on a staging environment if you have one — before activating the child theme on production.

If you're not sure which files you changed or whether the changes are still working correctly, that's a good sign you need a clean audit before proceeding. See our guide on how to isolate changes that are causing unexpected behavior.

How to Prevent Future Direct-Edit Temptation

The fastest way to stop the habit is to remove the opportunity. Add this line to your wp-config.php file (above the line that says "That's all, stop editing!"):

define( 'DISALLOW_FILE_EDIT', true );

This disables the Appearance → Theme File Editor and the Plugin File Editor for all users, including admins. It doesn't affect FTP access, but it removes the lowest-friction route to direct edits and closes the security door at the same time.

If you work with a team or freelancers, document the child theme and site-specific plugin workflow explicitly. The temptation to "just quickly fix it in the editor" is highest when someone is under time pressure. Having a clear, written process — even a one-page internal doc — prevents expensive mistakes.

When to Call a Professional

If your site is already broken because of a direct edit, or you've discovered that a previous developer left years of changes scattered across parent theme files you can't easily untangle, the safest move is a proper audit and migration — not more edits under pressure.

If you're not sure what's been changed, what's safe to move, or you just want it done correctly without the risk, get a free Mend diagnosis. A senior engineer will assess exactly what's in your theme files, tell you what needs to move and where, and quote a flat price before touching anything. Most migrations like this ship the same day.

For ongoing protection — including managed updates that catch theme compatibility issues before they go live — take a look at the Mend Care Plan.


Direct theme edits feel fast in the moment. But the update that wipes them, or the typo that takes down your site at midnight, always costs more than taking the right approach from the start. A child theme and a site-specific plugin take twenty minutes to set up properly. That's the investment that keeps your changes safe indefinitely.

Frequently asked questions

Will a child theme slow down my site?

No. A child theme adds no meaningful overhead. WordPress loads the child theme's files first and falls back to the parent for anything not overridden — this is a tiny file-system check that has no measurable effect on page speed.

Do I need a child theme if I'm using a page builder like Elementor or Beaver Builder?

For purely visual changes made through the builder's interface, usually not — those are stored in the database. But if you're adding custom PHP, filters, or enqueueing scripts, you still need a child theme or site-specific plugin to do it safely.

What if my theme doesn't offer updates — like a custom-built theme?

If the theme is truly bespoke and will never be updated through WordPress, direct edits are technically safe from the "overwrite on update" problem. You still risk the other issues: no syntax checking, no version history, and security exposure from the file editor. Using a site-specific plugin for PHP logic is still a better practice regardless.

How do I know if previous edits were made directly to my parent theme files?

Compare your theme files against the original download from the developer or theme marketplace. A diff tool (or a plugin like Theme Check) can highlight differences. If you don't have the original, check the developer's changelog for the current version and compare file modification dates via FTP — recently modified files in the parent theme folder are a strong signal.