Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
WPB Cup
25 Million+
Websites using our plugins
16+
Years of WordPress experience
3000+
WordPress tutorials
by experts

What is: functions.php

Editorial Note: We earn a commission from partner links on WPBeginner. Commissions do not affect our editors' opinions or evaluations. Learn more about Editorial Process.

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.php in WordPress?

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.

The Best Way to Add Custom Code Snippets to functions.php

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

The simplest way is to use WPCode, a powerful WordPress code snippet plugin that makes it easy for you to add custom WordPress features using code snippets without editing your theme’s functions.php file.

While you can add your own code snippets, it conveniently comes with a built-in code snippets library where you can find some of my most popular WordPress code snippets that will help you eliminate the need of separate plugins.

WPCode WordPress Code Snippets Library

For example, there are ready-made snippets that will help you keep your WordPress website secure, allow you to upload SVG images, choose your WordPress editor, and disable comments.

Once you install and activate the plugin, you can head over to the Code Snippets page and then click the ‘Add New’ button to create your first code snippet in WordPress.

Click 'Add New' in WPCode to create a new custom snippet

This will bring you to the ‘Add Snippet’ page.

Here you can choose a code snippet from the pre-made library or add your custom code.

Add custom code in WPCode

You need to start by entering a title for your custom code snippet, then paste your code snippet into the code box.

Be sure to also select the correct code type from the drop-down menu on the right.

Adding your first code snippet

To learn more about how to use WPCode, 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

Editorial Staff

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

The Ultimate WordPress Toolkit

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