functions.php vs Plugin: Why You Should Move Code to a WordPress Plugin
In Part 1, you created your first custom plugin. Now let’s fix a common mistake: putting everything in functions.php.
It works at first—but it doesn’t scale.
Why functions.php Is Risky
The functions.php file is tied to your active theme.
That means:
- Switch themes → your code disappears
- Update themes → your changes may break
- Delete themes → your functionality is gone
This is why sites unexpectedly lose features after a redesign.
The Rule to Remember
Themes control appearance. Plugins control behavior.
If your code affects functionality (not design), it belongs in a plugin.
What Should Go in a Plugin?
Move code to a plugin if it:
- Changes site behavior
- Should survive theme changes
- Is reused across pages or projects
Examples:
- Redirects
- Custom meta tags
- Body classes
- Script loading logic
Quick Example: Moving Code
From functions.php:
add_action( 'wp_head', function() {
echo '<meta name="custom-tag" content="example">';
});Move it to:
/wp-content/plugins/frontend-utility-plugin/includes/frontend-hooks.phpThen remove it from functions.php.
Now your feature stays—even if you change themes.
Why This Matters
Using plugins instead of functions.php helps you:
- Avoid breaking your site during theme changes
- Keep code organized and reusable
- Build cleaner, maintainable WordPress projects
What’s Next (Part 3)
Next, you’ll learn how to structure your plugin as it grows—without turning it into a messy single file.


