Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
Use a plugin for a feature that should keep working when you change themes; use the active theme’s functions.php for behavior that belongs to that theme. If you are customizing a parent theme, put the changes in a child theme instead. This is a lifecycle and ownership choice—not a choice with an established, universal performance winner.
Choose based on what owns the code
Ask one question first: Should this feature still work if the site changes themes? If yes, a plugin is usually the right home. If the code defines how one particular theme is set up or behaves, keep it with that theme. WordPress’s Theme Handbook recommends plugins for new features that should be available “no matter what the website looks like.” WordPress Theme Handbook.
| What the code does | Recommended location | Why |
|---|---|---|
| A site feature that should work across themes | Standalone plugin | Plugins can be activated independently of the active theme. |
| Theme setup, theme support, or design-specific behavior | Active theme’s functions.php |
WordPress loads this file for the active theme. |
| A change to a parent theme that must survive parent-theme updates | Child theme’s functions.php |
The separate child-theme code is not overwritten by updates to the parent. |
| Site-wide code that should remain active | Consider a must-use plugin | It is intended for site-wide functionality, but has distinct loading and activation constraints. |
When a plugin is the better choice
Put functionality in a plugin when it belongs to the site rather than its current design. Examples include a feature you want to retain after switching themes or code intended to be distributed for use on different sites. A plugin is managed separately from the theme, so changing the site’s appearance does not by itself make the feature stop running.
Free tools Windows power users keep installed
One-click scans. No signup required.
A basic plugin needs a main PHP file with a correctly formatted plugin header comment that includes at least the plugin name. The Plugin Handbook also documents activation, deactivation, and uninstall hooks for code that needs setup or cleanup at those lifecycle points: Plugin Basics.
#1 Best Overall
When functions.php is the better choice
The active theme’s functions.php is appropriate for setup and behavior that belongs to that theme, such as registering theme support. WordPress loads the active theme’s file on front-end and admin page views. That tight connection is useful for theme features, but it also means code placed there stops running when the theme is no longer active. See the Theme Functions documentation.
Do not treat functions.php as a replacement for the theme’s templates or as a site-wide code container by default. The deciding factor is whether the functionality should follow the theme or the site.
Rank #2
Protect customizations with a child theme
If you need to customize a parent theme, make the changes in a child theme rather than editing the parent directly. An update to the parent can overwrite edits made to its files. WordPress loads the child theme’s functions.php just before the parent’s; the child file augments the parent rather than replacing it. The Child Themes documentation explains this relationship.
Recommended Free Tools
- Add your own functions to the child theme; do not copy the parent’s function declarations into it.
- Declaring a function with a name already declared by the parent can cause a fatal error.
- Use distinct function, class, and variable names, including an appropriate prefix, to reduce naming conflicts.
When to consider a must-use plugin
A must-use plugin can suit site-wide code that should remain active. It behaves differently from a regular plugin: activation hooks do not run for must-use plugins, and WordPress automatically looks only for PHP files placed directly in the mu-plugins directory. A PHP file nested in a subdirectory is not automatically discovered. Check the Must-Use Plugins documentation before choosing this route.
Rank #3
Does either option make WordPress faster?
The WordPress documentation cited here explains where code belongs and how it is loaded; it does not establish that a plugin or functions.php is generally faster. Avoid choosing a location based on an assumed speed advantage. Choose based on ownership, theme-switch behavior, update safety, and how the code needs to be managed.
Quick Recap
Best Value
Rank #4
A practical decision checklist
- Would the feature still be useful with a different theme? Put site-wide functionality in a plugin.
- Does the code configure or extend one theme? Put it in that theme’s
functions.php. - Are you modifying a parent theme? Use a child theme and put your additions in its
functions.php. - Must the code remain active as site-wide functionality? Consider a must-use plugin, accounting for its loading and activation-hook constraints.
- Could a name collide with another function or class? Choose a distinct name and prefix before deploying the code.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

