Understanding functions.php — the brain of every WordPress theme

If WordPress themes were people, functions.php would be their brain that behind the scenes manages logic, behavior, and custom features, making each theme unique. While templates like header.php and single.php handle how your site looks, functions.php controls how it behaves.

What Exactly Is functions.php ?

Every WordPress theme can include a functions.php file. It’s written in PHP, and it runs automatically when your theme is active. In simple terms, it’s a place to add custom code that extends or modifies WordPress’s core functionality without touching the core files themselves.

The active functions.php file for the Twenty Twenty-Five theme — the central hub for loading assets, defining theme supports, and initializing features.
(click on the image to open in a new tab)

Think of it as your theme’s very own plugin. It is a sandbox where you can add features, or filters that only apply when that theme is active.

A functions.php file managing multiple theme features — from favicons and search filters to content filters like emoji-enhanced titles.
(click on the image to open in a new tab)

What You Can Do with It

Developers use functions.php for a variety of tasks, both simple and advanced. For example:

  • Add theme support for features like featured images, custom logos, or post formats:
Setting up theme defaults and enabling core features like post thumbnails, HTML5 markup, and automatic title tags in a theme’s setup function.
(click on the image to open in a new tab)
  • Register menus or widget areas:
Registering a navigation menu location in a theme, making it available for assignment within the WordPress menu editor.
(click on the image to open in a new tab)
  • Enqueue scripts and styles:
Loading the main stylesheet properly using wp_enqueue_style() — the recommended method for adding CSS in WordPress themes.
(click on the image to open in a new tab)
  • Create custom shortcodes or filters that enhance your site’s flexibility.
A custom filter inside functions.php adding an emoji to each title.
(click on the image to open in a new tab)
  • Include third-party libraries or load custom PHP files for better organization.
Organizing theme logic by including separate PHP files, such as shortcodes or widgets, using require_once get_template_directory() for cleaner structure.
(click on the image to open in a new tab)

When to Use functions.php (and When Not To)

If you’re making changes that belong specifically to your theme’s design orstructure, functions.php is perfect. But if you’re adding features that should persist across theme changes , like custom post types or analytics tracking, it’s better to use an MU-plugin instead.

Defining a custom post type (“Projects”) inside a must-use plugin, ensuring it persists across theme changes while supporting custom capabilities and REST API visibility.
(click on the image to open in a new tab)
Rule of Thumb: If the functionality is part of the theme’s identity, put it in functions.php.
If it’s part of your site, build it as a plugin.

Wrapping Up

functions.php is where developers make WordPress themes smarter by adding hooks, loading assets, and shaping how the site behaves behind the scenes.

For beginners, it’s often the first safe place to experiment with code. It’s a powerful file that transforms a basic theme.

Although my blog doesn’t support comments, feel free to reply via email or X.