Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
25 Million+
Websites using our plugins
Years of WordPress experience
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 is a theme functions file that acts like a plugin for your WordPress site and is automatically activated by your current theme.

A functions.php file is included with all WordPress themes and uses PHP code to add new features or change the default features on a WordPress site.

For example, a WordPress theme might add a bit of code to the theme’s functions.php file 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 code allows you to add post types, taxonomies, shortcodes, and more to improve your website.

Why You Normally Shouldn’t Directly Edit the functions.php File

The functions.php file is located in your theme folder and advanced users can add code snippets by directly editing the file.

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

WordPress tries to separate design and functionality whenever possible. This is a good approach, and it’s often best to use WordPress themes to customize the way your site looks, and plugins to determine how it functions.

Also, making a coding mistake in your functions.php file can lead to WordPress errors or cause the White Screen of Death that makes your website disappear. These errors can be as simple as a missing semicolon, so anyone editing the functions.php file should use extreme caution.

In summary, there are 3 reasons why it’s not a good idea to edit your functions.php file:

  • 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.

However, you may wish to edit the functions.php directly to make changes to one specific theme, such as adding custom fonts or a language translation file.

In that case, we recommend you use a child theme.

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

So, if you shouldn’t directly edit the functions.php file, how 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!