Beginner's Guide for WordPress / Start your WordPress Blog in minutes

What is: functions.php

In WordPress, functions.php or the theme functions file is a template included in WordPress themes. It acts like a plugin for your WordPress site that’s automatically activated with your current theme. The functions.php file uses PHP code to add features or change default features on a WordPress site.

For example, a WordPress theme might add a bit of code to the theme’s functions.php file in order to add a new widget area to the footer, or add a custom welcome message to the WordPress dashboard. The possibilities are endless!

What is Functions
The functions.php file automatically loads when you install and activate a theme on your WordPress site.

Editing the functions.php file using custom codes allows you to add post types, taxonomies, shortcodes, and more to improve your website.

Where Is the Functions.php File Located?

The functions.php file location is in your theme folder.

If you want to add a code snippet to your WordPress site, adding it to the functions.php file is one option.

But it’s usually not the best way to do it. WordPress tries to separate design and functionality whenever possible. This is the reason that we have themes, which determine the design, and plugins, which determine functions.

It’s best if you’re able to change your WordPress theme without changing the way your site functions, or change your plugins without affecting your site design.

There are many WordPress tutorials that will tell you to add code snippets to your theme’s functions.php file, but that’s usually not a good idea.

If you decide to edit your functions.php file, please use extreme caution. Here are 3 reasons why editing your functions.php file is not a good idea:

  • Edits to the functions file will be lost when the theme is updated.
  • Edits will be lost if you change your WordPress theme.
  • Making coding errors in the functions file can lock you out of your site.

Even something as simple as a missing semicolon could make your whole site disappear with an error called the “White Screen of Death”. If that does happen to you, we wrote a step-by-step guide on how to fix the WordPress White Screen of Death so you can regain access to your site.

Making a coding mistake in your functions.php file can also lead to other WordPress errors as well.

You should only edit a functions.php file if you have a child theme and the code snippets will only be used with the active child theme. For example, you may want to include snippets for custom fonts, stylesheets, or add a language translation file specifically for that particular child theme.

Why Site-Specific Plugins are Better (Functions.php Alternative)

So, if you shouldn’t edit functions.php, where are you supposed to add code snippets from online tutorials?

The answer is creating your own WordPress plugin.

This is often called a “site-specific plugin” because it’s specific to your own site, and won’t ever be shared in the WordPress plugin directory.

Using a site-specific plugin is the best solution because your code snippets are stored separately from your theme’s functions.php file. This means that they can be activated or deactivated, just like any other plugin. This guarantees that your code won’t disappear if you switch themes.

Unfortunately, WordPress doesn’t come with a site-specific plugin by default.

The good news is you can either create a site-specific WordPress plugin yourself, or download one from the WordPress plugin directory.

For beginners, we suggest downloading the Code Snippets plugin. The Code Snippets plugin is a much simpler solution and provides a better way to create, edit, and manage all your custom code snippets in WordPress.

Once you activate the Code Snippets plugin, you’ll see a new menu item labeled Snippets on your WordPress admin menu.

adding code snippets in wordpress with a plugin

The Code Snippets plugin provides you with an easy to use graphical interface, a full-featured code editor, and fields for the snippet name, description, and tags. You can even export your snippets to use them on other sites.

For step-by-step instructions, see our guide on how to add custom code snippets to WordPress.

We hope this article helped you learn all about the functions.php file in WordPress and how to add code snippets to your site! Check out the additional reading below to learn more.

You can also subscribe to our YouTube channel for step-by-step WordPress video tutorials, and follow us on Twitter and Facebook for the latest updates.

Additional Reading

The Ultimate WordPress Toolkit

Get FREE access to our toolkit – a collection of WordPress related products and resources that every professional should have!