r/Wordpress • u/Realistic-Excuse-396 • 3d ago
Child theme, Code Snippets plugin, or a custom plugin — where do you keep your custom code?
I keep going back and forth on this for client sites.
- Child theme functions.php: simple, but code disappears if the client switches theme.
- Code Snippets plugin: easy to toggle, but harder to version control.
- Small custom 'site plugin': survives theme changes, works with Git.
My current rule: anything about how the site looks (template overrides, small layout tweaks, CSS) goes in the child theme. Anything about how the store works (checkout changes, custom fields, WooCommerce hooks, integrations) goes in a small site plugin. That way a redesign never breaks the business logic.
What's your approach, especially on sites you hand over to clients?
6
u/b24rye 3d ago
Using Code Snippets is never a good idea in terms of performance & security. Better to use child themes & plugins. And the rule of thumb is: themes control presentation and layout, plugins control functionality and data.
10
u/BOLVERIN1 Jack of All Trades 3d ago
I never use Code Snippets or anything similar. You want to be able to store the changes in a git repo; otherwise, it screw you over eventually
Child theme if it's theme-specific functionality; plugins if it's project-specific
2
u/babelmonk 3d ago
Your split is pretty much mine. Looks in the theme, behaviour in a plugin, so a redesign can't take the checkout down with it.
A few things I'd add from running client sites:
mu-plugins for anything the client must not switch off. Security hardening, login changes, anything an integration depends on. A normal site plugin can still be deactivated from the Plugins screen by a client who's tidying up. A file in
wp-content/mu-plugins/loads every time and can't be disabled from the dashboard. I keep the business logic in a normal site plugin and only the "never turn this off" bits in mu-plugins, with a one-line loader if it needs more than one file.Snippets plugins store the code in the database. That's the bigger problem for me, more than version control. Copy a staging database over live (or the reverse) and your snippets go with it, so you can quietly overwrite a fix. I'll use one to try something out quickly, then move it into the site plugin once it works.
On block themes, the child theme matters less. Most of the styling lives in
theme.json, so I lock the design there. The catch at handover: anything the client changes in the Site Editor is saved in the database and overrides your theme files. If a template "won't update" after you deploy, check for a customised copy under Appearance > Editor and reset it.Whichever you pick, put a short README in the site plugin listing what each file does. Whoever inherits the site in two years will thank you.
2
u/Winter_Process_9521 3d ago
Your separation is right. I'd make the custom site plugin the single source of truth for business functionality, the child theme responsible for presentation, and Code Snippets a development convenience rather than a permanent architecture.
1
u/Jaypee_peros 3d ago
Same split here, with one tweak: the site plugin goes in mu-plugins on client sites. They can't accidentally deactivate it, it loads before everything else, and it's still just a folder in Git. (Only gotcha: mu-plugins doesn't scan subfolders, so add a one-line loader file in the root.)
Code Snippets I only use for quick experiments on staging. Anything that sticks gets moved into the plugin, because database snippets don't version and are easy to lose in migrations.
Good test for where code belongs: if switching themes would break it, and it isn't purely visual, it shouldn't live in the theme.
1
u/Psychological_Read_1 3d ago
In my opinion, the cleanest way to do it is to maintain a plugin in a private Git repository. I use Sync to quickly push updates to sites when needed, without logging in.
1
u/Over-Phase-2020 3d ago edited 3d ago
The split you described makes sense to me, and for handover I would add two things. I would not put secrets like API keys and webhook URLs directly in the plugin code, but in wp-config.php as constants that the plugin only reads, so the repository can be shared without leaking secrets and the keys survive a theme change. I would also add a short README to the plugin with one sentence per hook: what it changes, where it shows on the site or order, and how to switch it off safely. Hardly anyone reads it right away, but when something breaks after an update, that is the first thing the client or the next developer looks for, so before handover I would verify it by switching to the default theme on staging.
1
u/Minimum_Throat_9290 3d ago
Yeah, your split is the one that survives a redesign. I'd also put anything the shop can't go down without (checkout hooks, payment, redirects) in a must-use plugin, so it can't be deactivated from the dashboard by accident. And drop a short readme in that plugin listing what each hook does, because six months later neither you nor the client will remember. Code Snippets is fine for a quick test on your own install, but I wouldn't leave it on a site I hand over.
1
u/Early-Community9943 3d ago
Same split here, but I keep Code Snippets off client sites completely. Sooner or later someone toggles the wrong snippet and there's zero history of what changed.
1
u/MartinWolf_ 3d ago
Pretty much the same rule here, looks go in the child theme, behavior goes in a plugin. A few additions that saved me on handovers:
For the business-critical stuff I use a must-use plugin instead of a normal one. Files in mu-plugins load automatically and can't be deactivated from the admin, so nobody "cleans up the plugin list" and accidentally kills checkout. The tradeoff is that it's less visible, so I leave a note about it in the handover doc.
I name it after the client and the purpose, something like "Clientname Store Logic", with a short header comment listing what each file does. Six months later that's the difference between a 5-minute fix and an hour of grepping.
Code Snippets I keep for the client's own small tweaks, if they want something they can toggle themselves. My code never goes there, so the line between "what I own" and "what they own" stays clear.
And one file per feature inside the site plugin, so removing a feature later is deleting a file rather than surgery on one giant functions file.
1
u/Budget-Scar-146 3d ago
I follow pretty much the same approach. I keep design-related changes in the child theme and move functionality, integrations, and WooCommerce customizations into a small site-specific plugin. It makes future redesigns much easier because the business logic stays separate from the theme. For client sites, I also keep the custom plugin in Git so changes are easier to track and maintain.
1
u/balancebitsolutions 3d ago
I do the same split as most people here, but the reason I stopped using Code Snippets on client sites isn't really about where the code lives — it's about finding it again later.
When a snippet lives in the database, I can't search it properly, I can't see what changed and when, and I can't roll it back cleanly. I've inherited a client site where a snippet had been edited in the dashboard six months earlier, nothing in Git matched the live site, and tracking down why a form had stopped working took far longer than the fix.
So my rule now is simple: if I can't grep it, diff it and roll it back, it doesn't go on a client site. The site plugin is the only place that passes that test, with the child theme holding just the visual bits. Code Snippets is fine on my own test site, but that's where it stays.
1
u/dirtyoldbastard77 Developer/Designer 3d ago
Plugin or in the functions.php file, depends on the situation
1
u/markaritaville 3d ago
Context may be important. Large sites with numerous upgrades, and supported by a FT Developer or team where they already have github or similar... sure go the full route of plugin etc.
That being said i have a regional website that gets 350,000 views a month which is enough to pay full time bills for the family, and I just used code snippets. I have maybe 8 simple scripts. While I do have a tech background, there are 100 other things I maintaining on the site and being a one-man-show, my primary goal is to write content.
1
u/sslusser 2d ago
Mu-plugins for a lot of one-off type stuff. Full blown plugins for things I might use again. Like others have said if it has to do with the theme, then theme.
1
u/retr00two 3d ago
For front end design: json/child theme
For functionality: mu-plugin
Code in git, of course.
1
u/TerribleAd1635 2d ago
Couch cushions
1
u/une_danseuse 10h ago
Child theme
0
u/EusebiuOprinoiu Developer/Designer 3d ago
Complex functionality and general code that I can use on multiple websites go into a plugin.
Small tweaks that are site-specific and temporary snippets go into the Code Snippets plugin.