1. Code
  2. WordPress
  3. Theme Development

What Is the functions.php File in WordPress?

Scroll to top
Read Time: 4 min

Every WordPress theme comes with a function.php file or the theme functions file. In this post, I'll explain where to find it and why it's better to not modify it directly.

Though each theme has its own functions.php file, it is only the active theme's functions.php file that is activated when the site loads.

Inside functions.php is where you can define the custom (PHP) code snippets for adding new features to the site or changing default ones. With functions.php, you can do things such as the following:

  • insert header and footer scripts
  • specify a custom message to be shown on your WordPress dashboard
  • use WordPress hooks like excerpt_length (to change the length of your post excerpt from the default word count)
  • include features like post thumbnails, nav menus, and so on, through the use of add_theme_support()
  • specify functions to reuse in several theme template files and many more

Once added, the custom feature will be immediately applied to the site's theme and you'll see changes the next time you load your site.

Where to Find functions.php

The functions.php file is found in the /wp-content/themes/ folder within your WordPress installation directory, inside the folder for the currently active theme.

You can edit the file and add code snippets for whatever custom feature you want to add to your site. However, this is something that should generally be avoided. The functions.php file is a part of the theme, and if you edit it in a third-party theme, there are several risks. For one, you risk losing file changes when you either update the theme or change it. Worse yet, an error in the code could lead to a critical website error, effectively locking you out of your site.

If you do want to edit the functions.php file for a third-party theme, the best thing to do is to create a child theme. Other than that, simply avoid editing the functions.php file. Read more about child themes and overriding functions.php here on Envato Tuts+.

There are safer ways to add code snippets to your site's theme functions file. I'll discuss one of them in the next section.

Instead of directly editing functions.php, use a code snippet plugin like WPCode to easily add custom features to your WordPress site using code snippets, without touching your theme’s functions.php file.

The plugin allows you to add your own code snippets, and it also provides you with a built-in library of code snippets from which you can find some of the most popular snippets to use on your site, saving you the hassle of downloading separate plugins.

Code Snippets LibraryCode Snippets LibraryCode Snippets Library
Code Snippets Library

You can also search for other ready-made plugins by categories, which are listed in alphabetical order.

Under Code Snippets, you'll find a list of the code snippets already activated for your site. To add a new snippet, click the Add New button.

Add New SnippetAdd New SnippetAdd New Snippet
Add New Snippet

You'll be led to the Add Snippets page to either select one of their premade templates or start from scratch with a blank snippet.

Choose pre-made template or start blank snippetChoose pre-made template or start blank snippetChoose pre-made template or start blank snippet
Choose a premade template or start a blank snippet

If you choose a new (blank) snippet, you'll be taken to the page shown below. There you'll provide the name of your code snippet in the title box and then copy your code snippet into the code block. You'll also need to specify the code type (it should be PHP)

Paste in code snippetPaste in code snippetPaste in code snippet
Paste in code snippet

Click the Save Snippet button when done. The code snippet will be added to your theme functions file and applied to your site's theme.


Every WordPress theme comes with a functions.php file which is used to add custom features and functionalities to the site's current theme or to change default features.

Generally, you should avoid modifying functions.php for a third-party theme. This is to avoid losing useful file content (when you change or update the theme) and instigating a critical error in your site. Instead, use a code snippet plugin like WPCode to add custom snippets.

Did you find this post useful?
Want a weekly email summary?
Subscribe below and we’ll send you a weekly email summary of all new Code tutorials. Never miss out on learning about the next big thing.
Looking for something to help kick start your next project?
Envato Market has a range of items for sale to help get you started.