WPBeginner

Beginner's Guide for WordPress

  • Blog
    • Beginners Guide
    • News
    • Opinion
    • Showcase
    • Themes
    • Tutorials
    • WordPress Plugins
  • Start Here
    • How to Start a Blog
    • Create a Website
    • Start an Online Store
    • Best Website Builder
    • Email Marketing
    • WordPress Hosting
    • Business Name Ideas
  • Deals
    • Bluehost Coupon
    • SiteGround Coupon
    • WP Engine Coupon
    • HostGator Coupon
    • Domain.com Coupon
    • Constant Contact
    • View All Deals »
  • Glossary
  • Videos
  • Products
X
☰
Beginner's Guide for WordPress / Start your WordPress Blog in minutes
Choosing the Best
WordPress Hosting
How to Easily
Install WordPress
Recommended
WordPress Plugins
View all Guides

WPBeginner» Glossary» F» functions.php

What is: functions.php

46 Shares
Share
Tweet
Share
Pin

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

  • How WordPress Actually Works Behind the Scenes (Infographic)
  • 32 Extremely Useful Tricks for the WordPress Functions File
  • How to Add Header and Footer Code in WordPress (the Easy Way)
  • How to Easily Add Custom Code in WordPress (without Breaking Your Site)
  • Beginner’s Guide to Pasting Snippets from the Web into WordPress
  • WordPress Plugin vs Functions.php file (Which is better?)
  • 15 Useful WordPress Configuration Tricks That You May Not Know
46 Shares
Share
Tweet
Share
Pin
Popular on WPBeginner Right Now!
  • How to Start Your Own Podcast (Step by Step)

    How to Start Your Own Podcast (Step by Step)

  • Revealed: Why Building an Email List is so Important Today (6 Reasons)

    Revealed: Why Building an Email List is so Important Today (6 Reasons)

  • How to Properly Move Your Blog from WordPress.com to WordPress.org

  • Google Analytics in WordPress

    How to Install Google Analytics in WordPress for Beginners

About the Editorial Staff

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi. Trusted by over 1.3 million readers worldwide.

Over 1,320,000+ Readers

Get fresh content from WPBeginner

Featured WordPress Plugin
PushEngage
PushEngage
Increase your website traffic & revenue with push notifications. Learn More »
How to Start a Blog How to Start a Blog
I need help with ...
Starting a
Blog
WordPress
Performance
WordPress
Security
WordPress
SEO
WordPress
Errors
Building an
Online Store
Useful WordPress Guides
    • 7 Best WordPress Backup Plugins Compared (Pros and Cons)
    • How to Fix the Error Establishing a Database Connection in WordPress
    • Why You Need a CDN for your WordPress Blog? [Infographic]
    • 30 Legit Ways to Make Money Online Blogging with WordPress
    • Self Hosted WordPress.org vs. Free WordPress.com [Infograph]
    • Free Recording: WordPress Workshop for Beginners
    • 24 Must Have WordPress Plugins for Business Websites
    • How to Properly Move Your Blog from WordPress.com to WordPress.org
    • 5 Best Contact Form Plugins for WordPress Compared
    • Which is the Best WordPress Popup Plugin? (Comparison)
    • Best WooCommerce Hosting in 2020 (Comparison)
    • How to Fix the Internal Server Error in WordPress
    • How to Install WordPress - Complete WordPress Installation Tutorial
    • Why You Should Start Building an Email List Right Away
    • How to Properly Move WordPress to a New Domain Without Losing SEO
    • How to Choose the Best WordPress Hosting for Your Website
    • How to Choose the Best Blogging Platform (Comparison)
    • WordPress Tutorials - 200+ Step by Step WordPress Tutorials
    • 5 Best WordPress Ecommerce Plugins Compared
    • 5 Best WordPress Membership Plugins (Compared)
    • 7 Best Email Marketing Services for Small Business (2020)
    • How to Choose the Best Domain Registrar (Compared)
    • The Truth About Shared WordPress Web Hosting
    • When Do You Really Need Managed WordPress Hosting?
    • 5 Best Drag and Drop WordPress Page Builders Compared
    • How to Switch from Blogger to WordPress without Losing Google Rankings
    • How to Properly Switch From Wix to WordPress (Step by Step)
    • How to Properly Move from Weebly to WordPress (Step by Step)
    • Do You Really Need a VPS? Best WordPress VPS Hosting Compared
    • How to Properly Move from Squarespace to WordPress
    • How to Register a Domain Name (+ tip to get it for FREE)
    • HostGator Review - An Honest Look at Speed & Uptime (2020)
    • SiteGround Reviews from 4196 Users & Our Experts (2020)
    • Bluehost Review from Real Users + Performance Stats (2020)
    • How Much Does It Really Cost to Build a WordPress Website?
    • How to Create an Email Newsletter the RIGHT WAY (Step by Step)
    • Free Business Name Generator (A.I Powered)
    • How to Create a Free Business Email Address in 5 Minutes (Step by Step)
    • How to Install Google Analytics in WordPress for Beginners
    • How to Move WordPress to a New Host or Server With No Downtime
    • Why is WordPress Free? What are the Costs? What is the Catch?
    • How to Make a Website in 2020 – Step by Step Guide
Deals & Coupons (view all)
IPVanish Coupon
Get 20% OFF on IPVanish, one of the best VPN service providers for bloggers and WordPress users.
Theme Trust
ThemeTrust Coupon
Get 20% off on all ThemeTrust themes brought to you by Henry Jones.
Featured In
About WPBeginner®

WPBeginner is a free WordPress resource site for Beginners. WPBeginner was founded in July 2009 by Syed Balkhi. The main goal of this site is to provide quality tips, tricks, hacks, and other WordPress resources that allows WordPress beginners to improve their site(s).
Join our team: We are Hiring!

Site Links
  • About Us
  • Contact Us
  • FTC Disclosure
  • Privacy Policy
  • Terms of Service
  • Free Blog Setup
  • Free Business Tools
Our Sites
  • OptinMonster
  • MonsterInsights
  • WPForms
  • SeedProd
  • Nameboy
  • RafflePress
  • Smash Balloon

Copyright © 2009 - 2021 WPBeginner LLC. All Rights Reserved. WPBeginner® is a registered trademark.

Managed by Awesome Motive | WordPress hosting by SiteGround | WordPress CDN by MaxCDN | WordPress Security by Sucuri.