The right drawer for code

functions.php vs a Plugin: Where Custom WordPress Code Belongs, and What Breaks When It Is in the Wrong Place

Somewhere in your theme there is a file called functions.php, and somewhere in it is a snippet pasted in 2019 that now sends your leads to the CRM. Nobody remembers who added it. Everybody will remember the day the theme changes and the leads stop. Here is where that code should live instead.

November 13, 2026 · 8 min read

acmebakeryco.com · support thread
The morning after a new theme went live
The site looks better. The orders form went quiet.
We switched to a new theme last night and no catering requests have reached our email since.
The form still shows on the page. The code that sent entries to your inbox lived in the old theme's functions.php, and only the active theme's file loads.
Can we just paste it into the new theme?
It would work until the next redesign. Moving it into a small plugin keeps it running whatever theme is active.
Illustrative: a sample support thread for a fictional bakery

The short answer

Custom code that powers a feature, such as a form connection, a custom post type, a shortcode or a tracking tag, belongs in a plugin. Code that only affects the look of the site belongs in the theme's functions.php. WordPress.org's Theme Handbook says themes should only deal with the site's design, and only the active theme's functions.php loads, so theme-held features stop when the theme changes.

On this page
  1. A junk drawer with a PHP extension
  2. Design in the theme, everything else in a plugin
  3. What stops working the morning after a theme switch
  4. Moving the code into a plugin of its own
  5. What still has every right to live in functions.php
  6. When a tidy plugin is not the real fix
  7. Prices for moving code out of the theme

A junk drawer with a PHP extension

Every house has a drawer of batteries, takeout menus and one key nobody can match to a lock. Every older WordPress site has functions.php. Open it and the history reads like that drawer: a snippet from a forum to hide the admin bar, a block to register a "Projects" post type, a tracking tag for an ad platform the business left in 2021, and forty lines that hook the contact form into a CRM, pasted in by a helpful nephew and never touched since.

It works. That is the trouble. Code in functions.php runs as long as the theme it lives in stays active, so nothing reminds anyone it is there. Then a redesign arrives, or the theme vendor stops updating, or a new developer switches to a lighter theme for speed. The site looks better the next morning. The leads have stopped, and nobody connects the two for a week.

This page is about putting each piece of code in the drawer it belongs in. For the bigger picture of what a custom plugin is for, see the section overview.

Design in the theme, everything else in a plugin

WordPress.org has written the rule down, twice. The Plugin Developer Handbook, read in November 2026, says: "Any functionality you want to add or modify should be done using plugins." The Theme Handbook's page on custom functionality, read the same month, says that for features meant to work regardless of the site's design, "it is best practice to put the code in a plugin."

The Theme Handbook then gives the cleanest version: "The rule of thumb is that themes should only deal with the site's design." It is honest about the temptation, too: "Just because you can build plugin-like features in a theme doesn't mean you always should." And it explains why the rule matters: "WordPress will only load the currently active theme's" functions.php.

The inference follows, and we label it as one: code in a theme's functions.php stops running when a different theme is activated, because only the active theme's file loads. A plugin keeps running whatever theme is active, because it is not part of the theme at all.

If the feature should survive a redesign, it does not belong in the theme.

What stops working the morning after a theme switch

Here is what typically lives in a business site's functions.php, and what happens to each when the theme changes, by the inference above. None of it shows an error. It simply stops.

Common functions.php code on business sites and its fate after a theme change, inferred from WordPress.org's Theme Handbook
Code in functions.phpAfter a theme changeWhere it belongs
Form entries sent to a CRM or email platformLeads stop reaching the CRM; the form may still say thank youA plugin
A custom post type such as Projects or LocationsIts admin menu disappears because the code that registers it no longer runsA plugin
Shortcodes used inside page contentPages may show the raw shortcode text where the feature used to beA plugin
Analytics or ad tracking tagsTracking stops; reports show a sudden drop that looks like lost trafficA plugin, or a tag manager the plugin loads
Redirects or access rulesOld links and protected pages behave differentlyA plugin
Theme colors, fonts, layout tweaksReplaced by the new theme's design, as intendedThe theme

The shortcode case is common enough that our repair guides cover it for one popular builder: Divi shortcodes showing after a theme change. If you are planning a theme change, our WordPress theme migration service covers shortcode cleanup and testing on staging before launch; moving feature code into a plugin first makes that job smaller.

Warm shallow-focus developer desk with a dark laptop screen, a mechanical keyboard and hands sorting small paper index cards into two neat piles beside a notebook
Moving code out of a theme starts with sorting it: what is design, and what is a feature.

Moving the code into a plugin of its own

The move is less dramatic than it sounds. WordPress.org's handbook says "The simplest plugin is a single PHP file," and that it "just needs a Plugin Header, a couple of PHP functions, and some hooks to attach your functions to." Hooks are "a way for one piece of code to interact/modify another piece of code at specific, pre-defined spots," which is exactly what most functions.php snippets already use.

  1. 1

    Copy the site to staging

    Never move code on the live site. Take a backup you have restored at least once.

  2. 2

    Inventory functions.php line by line

    Label each block: design, or feature. Write down what each feature does in plain words and which pages rely on it.

  3. 3

    Create a site plugin with a proper header

    At a minimum, the handbook says, the header comment "must contain the Plugin Name." We add a version, the PHP requirement and the license.

  4. 4

    Prefix everything

    The handbook warns that "all variables, functions and classes are defined in the global namespace" by default and asks for a unique prefix "at least 4 letters long, though we recommend 5."

  5. 5

    Move features, delete the originals

    Each feature moves to the plugin and is removed from functions.php in the same step, so it never runs twice.

  6. 6

    Switch themes on staging to prove it

    Activate a default theme on the copy. Every feature should still work. If one does not, it is still hiding in the theme.

Done properly, the plugin also cleans up after itself. The handbook describes activation and deactivation hooks and says "The uninstall hook is best suited to delete all data permanently," so options a feature created are removed if the plugin ever is. That is part of the standard our custom plugin development work follows.

What still has every right to live in functions.php

This is not a campaign against functions.php. It exists for a reason, and the theme is the right home for the theme's own work. The test is simple: would you want this to change when the design changes? If yes, it belongs in the theme.

Keep in the theme

  • Loading the theme's own styles and fonts
  • Menu locations and widget areas the design defines
  • Image sizes used by the theme's layouts
  • Small visual tweaks tied to this design

Move to a plugin

  • Anything that sends data elsewhere: CRM, email, texting, payments
  • Custom post types, fields and taxonomies holding business content
  • Shortcodes and blocks used in page content
  • Tracking, redirects, access rules and admin tweaks

Design work in the theme is its own craft, covered by our WordPress theme customization and WordPress theme developer pages. A snippet manager plugin is a reasonable stopgap for a handful of lines. A business process with money or leads running through it deserves a real plugin, kept in version control.

When a tidy plugin is not the real fix

Sometimes the inventory is sobering. Three hundred lines in functions.php, a page builder, a dozen plugins doing overlapping jobs. Moving the snippets is still worth doing, but it is housekeeping in a house with structural problems. Our page on replacing plugin bloat covers the cleanup, and if most features come from add-ons, the free should I leave WordPress? check and our replacing WordPress service cover the other road.

Prices for moving code out of the theme

As of November 2026, a custom site plugin that gathers your functions.php features starts at $575 to build, depending on complexity, with a fixed written estimate before work starts; the plugin pricing guide explains what moves the number. If one of those features talks to a CRM or field software, our API integration plugins page covers it, and those connections go live the same day.

Once the code is in a plugin, it needs the same care as any other: plugin maintenance for new WordPress and PHP releases, and hosting and maintenance from $55 a month for the site around it. Make sure the agreement for the work says who owns the plugin code. DataCram is a web studio in San Antonio, Texas, building for the web since 1999. Call (210) 346-0848, or start with a free website health check.

Questions owners ask about custom WordPress plugins

Code that powers a feature, such as a CRM connection, a custom post type, a shortcode or tracking, belongs in a plugin. Code that only shapes the look of the site belongs in the theme. WordPress.org's Theme Handbook says the rule of thumb is that themes should only deal with the site's design.

WordPress only loads the active theme's functions.php, according to WordPress.org's Theme Handbook. By that logic, code in the old theme's file stops running once another theme is active. Features such as form connections, shortcodes and custom post types can stop without any error message.

Not in principle. WordPress.org's handbook says the simplest plugin is a single PHP file with a plugin header, a few functions and hooks. The work is in doing it carefully: inventorying the old code, prefixing names, testing on staging and proving it by switching themes on the copy.

Moving the same code from one file to another does not add work for the server; it runs either way. A careful move often removes dead snippets nobody needed, and lets each feature load its scripts only where it is used. If the site is slow, the cause usually lies elsewhere.

For a handful of small lines, a snippet manager is a reasonable stopgap and keeps code out of the theme. For anything that moves leads, orders or money, a dedicated plugin kept in version control is easier to test, review and hand to the next developer.

A custom site plugin starts at $575 to build, depending on complexity, with a fixed written estimate, as of November 2026. If a single snippet broke after a theme change or PHP upgrade, a fixed-price fix from $149 to $399 may be the better first step.

Keep reading

Free · No obligation

Find out what is hiding in your theme

Tell us what the site does and whether a redesign is coming. Someone at DataCram replies with what would move to a plugin, what stays in the theme and a fixed written estimate.

Which of these sounds like you? (pick any)

Rather talk now? Call (210) 346-0848.

CallGet a quote