Back to blog
WordPressBest PracticesMaintenance

Why functions.php snippets are a time bomb in your WordPress site

Pasting snippets into functions.php breaks on theme switches, has no version history, and brings down the whole site on a typo. Here is why and what to do instead.

· 6 min read

If your WordPress site has more than five custom snippets in functions.php, you have a maintenance bomb waiting to explode. Theme updates, child-theme migrations, and developer handoffs are where these snippets typically detonate. Here is why this happens and what to do instead.

The lifecycle of a typical snippet

You search Google for "how to redirect WooCommerce checkout for logged-out users" in 2022. The top result has a 12-line snippet. You paste it into your child theme's functions.php. It works. You move on.

Two years later you switch themes. The new theme does not include your custom functions.php. The redirect breaks. Customers reach the checkout in a broken state for two days before someone notices. You re-find the snippet. You paste it into the new theme. Everything is "fine" again. Until next time.

Every snippet in functions.php has this lifecycle. Each one is a small invisible dependency between your theme and your business logic. WordPress has a clean separation between content, presentation, and functionality — and pasting business logic into the theme breaks that separation deliberately.

Five real risks of the functions.php approach

1. Theme switch wipes them out. The most common cause of "the site went weird" after a redesign. The new designer does not know about your snippets because they are buried inside an old theme.

2. No version history. When the snippet has a bug, there is no commit log telling you who added it, when, and why. Was that meta query added for SEO or for a one-time campaign that ended last quarter? You cannot tell.

3. Errors take down the whole site. A typo in functions.php produces a fatal that breaks both front end and admin. A typo in a plugin only breaks that plugin (and only if it is active).

4. Plugin conflicts are hard to debug. WordPress lets you deactivate plugins one at a time to isolate a conflict. There is no equivalent for snippets in functions.php — you have to comment them out manually, save, refresh, and put them back.

5. Cannot be reused. If you have ten client sites that all need the same redirect snippet, you copy-paste it into ten functions.php files. The day a customer asks you to change the behavior, you have to track down all ten copies. Most agencies have at least one snippet that is mysteriously different in three sites because someone updated it once and forgot the other seven.

The right way: turn each snippet into a plugin

Every snippet is a small functionality. Functionality belongs in plugins. The mental rule is: if you would copy it between sites, it should be a plugin.

The reason this used to be impractical is that scaffolding a plugin from scratch (boilerplate, activation hooks, options page if needed, internationalization, uninstall) used to take 20-30 minutes per snippet. With AI plugin generation in 2026, you describe the snippet's behavior in two sentences and get a proper plugin in two minutes. The cost is €1-€3 of credits per plugin, dramatically less than the time you were going to spend.

What this looks like in practice

The 12-line redirect snippet from the example above becomes a 60-line plugin (with proper hook lifecycle, an admin toggle to disable it without uninstalling, and an uninstall handler that cleans up its options). The conversion takes 2-4 minutes. The plugin then lives in /wp-content/plugins, survives theme switches, has its own GitHub repo or zip in your toolbox, and can be installed across all your client sites in seconds.

The migration path

Open your current functions.php. Pick one snippet at a time. Generate a plugin from a one-paragraph description. Activate the new plugin in a staging environment. If it works, delete the snippet from functions.php. Repeat until functions.php contains only true theme code (font enqueues, body class filters, image-size registration). For a typical WordPress site this takes one to two hours total and removes a permanent class of risk from your operations.

The exception: temporary fixes

If you need a snippet for 24 hours to debug something, paste it into functions.php. Delete it the next day. The rule against snippets is for snippets that have lived in functions.php for more than a week. Temporary scratch code is fine — but very few snippets actually leave when their author plans to remove them.