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
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
- A junk drawer with a PHP extension
- Design in the theme, everything else in a plugin
- What stops working the morning after a theme switch
- Moving the code into a plugin of its own
- What still has every right to live in functions.php
- When a tidy plugin is not the real fix
- 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.
| Code in functions.php | After a theme change | Where it belongs |
|---|---|---|
| Form entries sent to a CRM or email platform | Leads stop reaching the CRM; the form may still say thank you | A plugin |
| A custom post type such as Projects or Locations | Its admin menu disappears because the code that registers it no longer runs | A plugin |
| Shortcodes used inside page content | Pages may show the raw shortcode text where the feature used to be | A plugin |
| Analytics or ad tracking tags | Tracking stops; reports show a sudden drop that looks like lost traffic | A plugin, or a tag manager the plugin loads |
| Redirects or access rules | Old links and protected pages behave differently | A plugin |
| Theme colors, fonts, layout tweaks | Replaced by the new theme's design, as intended | The 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.

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
Copy the site to staging
Never move code on the live site. Take a backup you have restored at least once.
- 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
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
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
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
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
- Fewer moving partsToo Many WordPress Plugins? How to Replace Several Overlapping Ones With One That FitsToo many WordPress plugins slow sites and collide on updates. How to sort keep, merge and delete, what one plugin can replace, and when a rebuild wins.
- The offer, step by stepCustom WordPress Plugin Development Services, From the First Question to the HandoverWordPress plugin development services: discovery, a fixed written estimate, handbook-standard code, testing on a staging copy and a clear handover.
- Connections, built inWordPress API Integration Plugins That Put Each Lead in Your CRM the Minute It ArrivesA custom plugin that sends WordPress forms and orders to your CRM, field software, email or texting through their APIs. Live the same day, from $575.
- WooCommerce, extendedCustom WooCommerce Extensions for the Store Rule Your Staff Still Enforces by HandCustom WooCommerce extensions for pricing rules, shipping limits and checkout fields, built HPOS-compatible on WooCommerce's own APIs. From $575.
- Blocks, made to fitCustom Gutenberg Blocks Your Editors Can Fill In and Cannot Knock Out of LineCustom WordPress blocks built on block.json, as the Block Editor Handbook describes: fields your team fills in, a design they cannot break. From $575.
- Booking, built to your rulesCustom WordPress Booking Plugins for Schedules a Calendar Grid Cannot FollowWhen Bookly or Amelia at their published prices is enough, when a custom WordPress booking plugin wins, and where Kairos AI chat fits. From $575.
- Everything in Custom WordPress PluginsSee the section
From the Insights desk
- Did AI Kill WordPress? A Data-Driven Analysis of Traffic, Plugins, and Market Share DeclineWordPress is not dead, but the platform is under structural pressure from AI, new site builders, and changing search behavior. A data-driven look at the signals.
- How AI Agents Are Replacing WordPress Sites: A Practical 9-Step Migration Guide for Small BusinessesAI-driven agents are beginning to perform the discovery, support, and sales tasks that once required dozens of static WordPress pages. Here is a practical 9-step migration path.
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.