Using the WordPress functions.php file

Watch out! This tutorial is over 5 years old. Please keep this in mind as some code snippets provided may no longer work or need modification to work on current systems.
Tutorial Difficulty Level    

functions.php or the theme functions file is a template used by WordPress themes. It acts like a plugin and gets automatically loaded in both admin and front-end pages of a WordPress site. Usually this file is used to define functions, classes, actions and filters to be used by other templates in the theme. It can be used to add features and extend the functionality of both the theme, and the WordPress installation.

The functions.php file can be found in your theme’s folder (it is advisable to create a child theme before editing, then edit the CHILD’s functions file).

You can add both built in WordPress functions and regular PHP functions to hooks and filters that are predefined throughout the WordPress core. Although every theme you have installed on your site has its own functions.php file, only the active theme’s file will run its code.

If your theme doesn’t have a functions.php file you can simply create a plain-text file named functions.php and add it to your theme’s directory.

Some of the things you can do with a functions.php file include use WordPress actions and filters, you can enable post thumbnails, post formats, and navigation menus. Editing of the file can be done via command line (if you have ssh access to your web server, or by using a file manager plugin).

Let’s use add some code from one of the other WordPress tutorials to our child theme’s functions.php now. Append the following to the file, and do not close the php tags.

Now, you must be absolutely sure of your code before saving the file. If there are any errors at all, not only will your website stop working, but you won’t be able to get back into the dashboard!