functions.php
> Answer capsule: functions.php is a theme file WordPress loads on every page view. It lets you register menus, add shortcodes, enqueue scripts and stylesheets, hook into WordPress actions and fi...
functions.php
functions.php is a PHP file included in every WordPress theme that loads automatically on every page request — both front-end and admin. WordPress treats it as a lightweight plugin attached to your active theme, giving you a place to add custom code without building a standalone plugin.
Answer capsule:
functions.phpis a theme file WordPress loads on every page view. It lets you register menus, add shortcodes, enqueue scripts and stylesheets, hook into WordPress actions and filters, and extend core behavior — all without installing a separate plugin. As of WordPress 6.0+, it works in both classic and block themes.
What does functions.php do in WordPress?
WordPress calls functions.php during the after_setup_theme phase, before most other content loads. That timing means anything you register there — nav menus, image sizes, widget areas, custom post types — is available site-wide. We see this pattern on nearly every client site we manage: even simple business sites end up with 10–20 custom lines in functions.php within the first month.
Where is functions.php located?
The file lives at /wp-content/themes/your-theme-name/functions.php. Every theme can have one. If you’re using a child theme — which you should be, to protect customizations from update overwrites — your child theme’s functions.php loads before the parent theme’s file.
A minimal example
Adding a custom script to your site looks like this:
function wpschool_enqueue_scripts() {
wp_enqueue_script( 'my-script', get_template_directory_uri() . '/js/custom.js', [], '1.0', true );
}
add_action( 'wp_enqueue_scripts', 'wpschool_enqueue_scripts' );
This pattern — define a function, then attach it to a hook with add_action() — is the backbone of functions.php work.
When should you use functions.php vs. a plugin?
Use functions.php for customizations tied to the theme’s visual behavior: custom image sizes, menu registration, template-specific scripts. Use a plugin for functionality that should survive a theme switch — custom post types, shortcodes, redirects. We’ve recovered multiple client sites that lost data because post types were registered in functions.php, then the theme changed. Per the WordPress Theme Handbook, theme functions should handle theme-specific features only.
One gotcha we surface on client audits: a syntax error in functions.php — a missing semicolon, an unclosed bracket — produces a white screen or 500 error for the entire site. Always edit via a child theme and test changes in a staging environment before pushing to production.
Related terms
- Child theme — the correct place to put custom functions.php code on any third-party theme
- WordPress hooks — the
add_action()/add_filter()system functions.php relies on - wp_enqueue_scripts — the correct hook for loading CSS and JS
- Plugin — the better home for functionality independent of your theme
- Staging environment — where to test functions.php edits safely
Additional reading: How to edit functions.php in WordPress · Child theme tutorial · WordPress hooks explained
Last verified: April 2026