The functions.php vs plugin choice sounds technical, but the deciding question is simple. If you switched to a completely different theme tomorrow, should this code keep working? If the answer is yes, it probably belongs in a plugin. Let's look at why, and at the options in between.

What functions.php Is For

Every theme can include a functions.php file. The WordPress Theme Handbook explains that it behaves like a plugin, adding features and changing default behaviour, but only while that theme is active.

That makes it the right home for code that is genuinely part of the theme:

Three cards comparing functions.php, a site-specific plugin and a must-use plugin with examples of code for each
Choose by what the code does, not by which file is quickest to open.

If you use a child theme, its functions.php loads in addition to the parent theme's, and before it. It does not replace the parent file. The handbook also recommends prefixing your function names, so they do not clash with other themes or plugins.

Why Snippets Disappear on Theme Change

Because functions.php only runs for the active theme, any feature you put there stops when the theme changes. The Theme Handbook says it directly: if you are creating features that should be available no matter what the website looks like, it is best practice to put them in a plugin.

A house-shaped structure being swapped for a new one while a small red component is left behind fading on the floor, representing code lost on a theme change
Switch theme, and every feature hiding in the old theme's functions.php goes with it.

Typical things that vanish:

There is a second risk. If you edit a parent theme's functions.php directly, a theme update can overwrite your changes. A child theme protects against that, but not against a theme change.

What a Site-Specific Plugin Is

A site-specific plugin is a small plugin written just for your website. It holds the features that belong to the site rather than its design. According to the Plugin Handbook, a plugin lives in wp-content/plugins, needs a header comment so WordPress recognises it, and works regardless of the active theme.

<?php
      /**
       * Plugin Name: Example Site Features
       * Description: Custom post types and shortcodes for example.com.
       * Version:     1.0.0
       */

      if ( ! defined( 'ABSPATH' ) ) {
          exit;
      }

      add_action( 'init', 'examplesite_register_post_types' );
      function examplesite_register_post_types() {
          register_post_type( 'examplesite_project', array(
              'label'  => 'Projects',
              'public' => true,
          ) );
      }

Keep each plugin focused. The Plugin Handbook encourages plugins to do one job well. On a bigger site, two or three small, clearly named plugins are easier to manage than one huge file. If you are unsure whether you need a bespoke plugin at all, my guide on when you need a custom WordPress plugin helps you decide.

Code Snippet Plugins: Convenient but Risky?

Code snippet plugins let you add PHP through a screen in wp-admin, without touching files. They are popular because they are easy, and they do keep code separate from the theme.

The trade-offs are worth knowing:

A good middle ground: use a snippet plugin for small, low-risk tweaks, and move anything business-critical, such as integrations or content types, into a proper plugin that lives in version control.

Must-Use Plugins for Critical Code

Must-use plugins, often called mu-plugins, live in wp-content/mu-plugins. WordPress's Advanced Administration handbook explains how they differ from normal plugins:

Underground vault with a glowing red core behind heavy layered doors, representing a must-use plugin that always loads
Must-use plugins always run, which is exactly why they need to stay small and reviewed.

That makes them a good fit for small pieces of critical code, such as security settings or behaviour the site must never lose. The same features are also a risk. Because they are always on and easy to miss, keep them small, documented and in version control, and review them during security checks.

A Decision Checklist: functions.php vs Plugin

When you are about to add a snippet, run through these questions.

Seven-question decision checklist for choosing between functions.php, a plugin and a must-use plugin
If the first four questions get a yes, use a plugin.

If you already have a long list of plugins and snippets, my guide to having too many WordPress plugins explains why the number matters less than quality.

How to Move Code Safely

Moving code from a theme into a plugin is usually simple, but the order matters. If the same function is declared in both places at once, PHP stops with a fatal error.

Five-step process for moving code from functions.php to a plugin: back up, create plugin, move code, activate and deploy
Cut, do not copy. One function, one home.

If you work across several sites or with a team, a consistent approach helps. My article on a WordPress development process that scales covers version control and deployments.

Frequently Asked Questions

Is it bad to add code to functions.php?

No, as long as the code is about the theme itself, such as registering menus, image sizes or theme support. It becomes a problem when you put site features there that should keep working whatever theme you use.

Will my code be lost when the theme updates?

If you edited the parent theme's functions.php directly, a theme update can overwrite your changes. A child theme protects theme-related code from updates, and a plugin protects feature code from both updates and theme changes.

Are code snippet plugins safe?

They can be useful for small tweaks, but they store and run code from the database and give anyone with access a way to run PHP on your site. Limit who can use them, keep snippets small and documented, and move anything critical into a proper plugin.

When should I use a must-use plugin?

For small pieces of code that must always run and should never be switched off by accident, such as security hardening or essential site behaviour. Keep them small and documented, because they are easy to overlook.

Does a site-specific plugin slow down my site?

Not because it is a plugin. The same code costs the same whether it runs from functions.php or a plugin file. What affects speed is what the code does, not where it lives.

Final Thoughts

The functions.php vs plugin decision comes down to dependence. Theme-related code belongs in the theme, ideally a child theme. Site features belong in a small site-specific plugin. Critical always-on code can go in a must-use plugin, kept small and documented. Put each piece of code in the right home and theme changes stop being scary.

If you have years of snippets scattered across themes and plugins, my custom plugin development service can tidy them into well-organised, documented plugins.

Official References

Sources checked on 29 October 2026: