WordPress functions.php: What It Is and How to Edit It Safely

Summarize with:

The functions.php file is like a mini-plugin built into your WordPress theme. It lets you add custom features and change how your site behaves using PHP — without installing a separate plugin for every little thing. But because it runs on every page load, a single typo can take your whole site down. This guide explains what functions.php is, where to find it, how to edit it safely (with a child theme), when to use it versus a plugin, and some useful snippets to get started.

⚠️
Back up before editing

A single syntax error in functions.php can trigger the white screen of death and lock you out of your dashboard. Always back up the file (or the whole site) before editing, add one snippet at a time, and test after each change.

What is the functions.php file?

The functions.php file works like a mini-plugin for your WordPress theme. It’s a PHP file that holds custom functions — bits of code your site runs to add features, change default behavior, or hook into WordPress. Unlike a regular plugin, which works no matter which theme is active, functions.php is theme-specific: its code only runs while that theme is active.

Every WordPress site actually has more than one functions.php. There’s one in WordPress core (inside wp-includes) that you should never touch, one in your active theme, and — if you use one — one in your child theme. When WordPress loads a page, it processes the parent theme’s functions.php and the child theme’s, which lets a child theme add or override behavior without changing the parent.

With functions.php you can register menus and widgets, enqueue styles and scripts, add image sizes, change the login logo, disable the admin bar, tweak WooCommerce, and much more — often replacing several small single-purpose plugins.

Where is the functions.php file located?

Your theme’s functions.php lives in the theme folder:

/wp-content/themes/your-theme/functions.php

If you use a child theme, its file is at /wp-content/themes/your-child-theme/functions.php. There’s also the core file at /wp-includes/functions.php — inspect it if you suspect malware, but never edit it: WordPress overwrites core files on every update, so your changes would be lost (and could break the site). Learn more about this directory and everything it holds in our guide to the wp-content folder.

You reach these files through your hosting File Manager (in cPanel) or an FTP client like FileZilla.

Why you should use a child theme

Here’s the most important thing to understand about functions.php: edits to your theme’s functions.php are erased when the theme updates. If you add custom code to a theme you bought or downloaded, the next theme update overwrites it and your changes vanish.

The solution is a child theme — a small theme that inherits everything from the parent but keeps its own functions.php and style.css. You put your custom code in the child theme’s functions.php, and it survives parent-theme updates. In a child theme, functions.php only needs your additions, not a copy of the parent’s code (both load together).

💡
Block themes are different

In modern block themes, many customizations (colors, fonts, spacing) live in theme.json instead, so functions.php is optional. You can still add one for PHP hooks, enqueuing assets, or custom behavior when you need it.

How to edit functions.php safely

There are three common ways to edit the file. Whichever you choose, back up first.

1. FTP or File Manager (recommended). Connect via FTP or open your File Manager, go to /wp-content/themes/your-child-theme/, download functions.php, edit it locally in a code editor (VS Code, Sublime, Notepad++), then upload it back. This is the safest method: if something breaks, you still have the original and can re-upload it.

2. The Theme File Editor (use with caution). In the dashboard, go to Appearance → Theme File Editor, select your theme, and click functions.php. You can edit in the browser and click Update File. Convenient, but risky: a syntax error here can instantly break the site and lock you out of the very editor you’d use to fix it. Only make small, well-understood edits this way — never on a live site if you can avoid it.

3. A code snippets plugin (safest for beginners). Plugins like Code Snippets let you add PHP without touching functions.php at all. The code runs independently of your theme, so it survives theme changes and, if a snippet causes an error, the plugin can deactivate it automatically instead of crashing the site.

When to use functions.php vs a plugin

Both functions.php and plugins run PHP, so which should you use? A simple rule:

  • Use functions.php (in a child theme) for code that’s specific to the theme — enqueuing the theme’s styles, registering its menus, theme-related tweaks. If you switch themes, this code shouldn’t come along.
  • Use a plugin (or Code Snippets) for functionality you want to keep regardless of theme — analytics, custom post types, shortcodes, anything site-wide. This way, changing your theme doesn’t remove the feature.

For code that must never be disabled, developers also use mu-plugins (must-use plugins), which load automatically and can’t be turned off from the dashboard.

Useful functions.php snippets

Here are a few safe, common snippets to get started. Add them at the end of your child theme’s functions.php, one at a time, testing after each.

Disable the admin bar for non-admins:

add_action('after_setup_theme', function() { if (!current_user_can('manage_options')) { show_admin_bar(false); } });

Limit post revisions (lighter database — you can also do this in wp-config.php):

add_filter('wp_revisions_to_keep', function($num, $post) { return 5; }, 10, 2);

Add a custom image size:

add_action('after_setup_theme', function() { add_image_size('custom-thumb', 400, 300, true); });

Enqueue the child theme stylesheet (a classic use — loads your CSS properly):

add_action('wp_enqueue_scripts', function() { wp_enqueue_style('child-style', get_stylesheet_uri()); });

What to do if functions.php breaks your site

If you save a bad edit and see a white screen or a critical error, don’t panic. Connect via FTP or File Manager, open the theme’s functions.php, and remove the code you just added (or re-upload your backup). The site comes back as soon as the syntax error is gone. Since WordPress 5.2, you may also get a Recovery Mode email with a link to access the dashboard in safe mode. Reading your WordPress error logs will point to the exact line at fault.

Room to build without breaking things

Editing functions.php is much less stressful with backups you can roll back and staging to test on. Copahost WordPress hosting includes automatic backups, cPanel and FTP access, and support that helps when a snippet goes sideways.

See web hosting plans

Frequently asked questions

Where is the functions.php file in WordPress?
In your theme folder, at /wp-content/themes/your-theme/functions.php, or in your child theme at /wp-content/themes/your-child-theme/functions.php. There’s also one in WordPress core under /wp-includes, but you should never edit that one.

Will my functions.php changes be lost when the theme updates?
Yes, if you edit the parent theme’s functions.php directly. That’s why you should put custom code in a child theme’s functions.php or in a code snippets plugin, both of which survive theme updates.

Is it better to use functions.php or a plugin?
Use functions.php (in a child theme) for theme-specific code, and a plugin or Code Snippets for functionality you want to keep even if you change themes. Site-wide features belong in a plugin.

Why did editing functions.php break my site?
A syntax error — a missing semicolon, bracket, or an extra PHP tag — is the usual cause, and it triggers a white screen or critical error. Remove the code you added via FTP or restore your backup, and the site returns.

Can I edit functions.php without FTP?
Yes, through Appearance, Theme File Editor in the dashboard, but it’s risky because an error can lock you out. A safer no-FTP option is a code snippets plugin, which isolates your code from the theme files.

Related guides

The functions.php file connects to several WordPress topics — see our guides on the wp-config.php file, the .htaccess file, the white screen of death, and our hub of common WordPress errors. Read also WordPress user roles and permissions.

Conclusion

The functions.php file is one of the most useful tools in WordPress — a theme’s own mini-plugin for adding custom features with PHP. The keys to using it safely are simple: always work in a child theme so updates don’t erase your code, back up before editing, add one snippet at a time, and reach for a code snippets plugin when you want your customizations to outlive the theme. With those habits, functions.php becomes a powerful, low-risk way to shape exactly how your site works.

Share the Post:
Picture of Gustavo Gallas

Gustavo Gallas

Graduated in Computing at PUC-Rio, Brazil. Specialized in IT, networking, systems administration and human and organizational development​. Also have brewing skills.