- Article
- Intermediate
- 3 minutes read
- Reviewed August 3, 2026
WordPress custom code is often placed in a theme's functions.php file because that file is easy to access and loads automatically with the active theme.
That does not mean every customization belongs there.
The correct location depends on whether the code controls presentation, provides durable functionality or forms part of the deployment infrastructure.
What functions.php Is For
The theme functions file is loaded as part of the active theme.
It is appropriate for theme-specific setup such as:
- Registering theme support.
- Enqueuing theme styles and scripts.
- Registering navigation locations.
- Defining image sizes used by the design.
- Adding presentation-related hooks.
- Configuring block styles or editor behavior for that theme.
When the theme changes, this code stops loading.
What Belongs in a Custom Plugin
Use a plugin for functionality that should survive a redesign.
Examples include:
- Custom post types and taxonomies.
- Business rules.
- External API integrations.
- Form processing.
- Custom user capabilities.
- Scheduled synchronization.
- Data validation and migrations.
- Administration tools unrelated to theme design.
- Reusable organization-specific features.
A custom plugin creates a clear package with its own version, documentation and release process.
The Theme-Switch Test
Ask:
Should this feature continue to exist if the site activates a different theme tomorrow?
If yes, the code usually belongs in a plugin.
A theme may still provide templates and styles for the feature, but the underlying data and behavior should remain registered independently.
Child Themes
A child theme is useful for modifications that depend on a parent theme's presentation system.
It is not a general substitute for a custom plugin. Moving business logic into a child theme still ties it to the active theme family.
Must-Use Plugins
Use mu-plugins for required infrastructure managed through deployment rather than ordinary dashboard activation.
Examples include mandatory environment configuration or an organization-wide integration. Remember that normal activation hooks and update notices do not work in the same way.
Code Snippet Plugins
Snippet-management plugins can be convenient for small, controlled customizations.
They provide an interface, enable or disable controls and sometimes error protection. However, important project code should still have:
- Version control.
- Documentation.
- Review.
- Environment testing.
- A clear owner.
A long collection of anonymous dashboard snippets can become harder to maintain than a small custom plugin.
Avoid Editing Third-Party Files
Do not place customizations directly inside WordPress core, a third-party plugin or a parent theme.
Updates can overwrite them, and future maintainers may not know the change exists.
Use hooks, template overrides, child themes or an integration plugin.
Organizing a Project Plugin
A project-specific plugin can begin simply:
project-functionality/
├── project-functionality.php
├── src/
├── assets/
└── readme.md
As it grows, separate concerns such as content registration, integrations, administration and migrations. Avoid turning one file into an unstructured collection of unrelated callbacks.
Deployment and Ownership
Whichever location you choose, define:
- Who maintains the code.
- How it is tested.
- How it is deployed.
- How versions are tracked.
- What data it owns.
- What happens during deactivation and uninstall.
Placement is an architectural decision, not only a coding preference.
Frequently Asked Questions
Is functions.php technically a plugin?
No. It is part of the active theme, although it can use many of the same WordPress APIs and hooks.
Can a plugin contain CSS and templates?
Yes. Plugins can provide presentation required by their functionality, while themes may override or integrate with it.
Should every client website have a custom plugin?
Not necessarily. Create one when the project has durable custom functionality that is not owned by a maintained third-party plugin.
Continue Learning
Previous: WordPress Hooks, Actions and Filters