How to Open and Edit Your Functions.php File

Share on facebook
Share on twitter
Share on email

As a WordPress administrator, you should know how to open and edit your functions.php file. This article looks at the occasions you might want to do that, and how to do it safely. Let’s begin with a brief introduction of this critical file and where you can find it.

WP Functions File Defined

Every WordPress install has a functions.php file in its themes folder (/wp-content/themes). Its primary purpose is to add functions and features to the active template using PHP code. The file already includes code specific to the active WordPress theme, but you can also add custom code.

Functions.php vs Plugins

Your functions PHP works like a plugin but is theme-dependent. That means each functions.php file belongs to its theme. Plugins are different as they continue to work across all active themes. So, any modifications to a functions PHP file don’t carry over if you switch to another theme.

Here are 6 examples of what your functions.php file can do.

  1. Add custom navigation menus
  2. Add profile fields to support WP authors
  3. Add widget-ready areas or sidebars to posts
  4. Customise the WordPress Admin Bar
  5. Modify your WordPress site ‘under maintenance’ message
  6. Change the behaviour of an active plugin

Add Code Snippets Using a Plugin

It’s easy to edit or modify your functions PHP files with code snippets, but there’s a warning. If the newly added code is wrong, or something gets altered by accident, it could break your site. That’s a problem if you forgot what you did or are unable to find the broken code. Get someone with experience to update this file if you’re not confident making the changes.

MAKE A FRESH BACKUP OF YOUR WORDPRESS WEBSITE BEFORE YOU START. AT LEAST MAKE A COPY OF THE FUNCTIONS PHP BEFORE WORKING ON IT.

Log in to your WP Dashboard then go to Appearance => Theme Editor.

A warning message displays for first-time visitors to the WP Theme Editor.

Click ‘I understand’ to continue.

Confirm—or switch to—the correct theme in the Select theme to edit dropdown (top right).

Now click the Theme Functions link to the right of the Edit Themes screen.

Your next move depends on whether you need to edit existing code or add a new snippet.

How to edit existing code (advanced users only)

Functions PHP files are huge, so the fastest way to find your code is with a quick search.

Use the CTRL + F keyboard shortcut to bring up the file search box.

Type or paste part of the code into the search box, and press Enter on the keyboard.

Modify your code and click the Update File button to save the changes.

Check the site to confirm the update was successful.

How to add code snippets to the functions PHP

Click inside the file and use the keyboard shortcut CTRL + End to go to the end of the page.

Copy and paste the new code at the bottom of the file.

Click the Update File button to save the changes.

Check the site to confirm the update was successful.

Editing Functions PHP Using FTP and File Manager

The only reason to edit your WP functions.php from the web hosting server is if there are problems. For example, the file doesn’t show in the WP Dashboard. Or maybe you can’t access the Editor screen or are unable to save the theme or child theme after changing it.

WARNING! MAKE A FRESH BACKUP OF YOUR WORDPRESS WEBSITE BEFORE YOU START. AT LEAST MAKE A COPY OF THE FUNCTIONS PHP BEFORE WORKING ON IT.

FTP options for WordPress websites and blogs

You can use either the cPanel File Manager or a standalone third-party FTP client.

File path: /public_html/wp-content/themes/theme-name/functions.php

Using a third-party FTP client

  • Download a copy of the functions.php file to your computer (see file path above)
  • Rename it to copy-functions.php (this is your backup file)
  • Download another copy of the functions.php file to your computer using FTP
  • Open and edit the file in a code editor like Notepad++ from your desktop
  • Close the file and save the changes
  • Upload the modified functions.php file to your FTP server

Using the Control Panel (cPanel) File Manager

  • Open File Manager from inside your cPanel account
  • Navigate to the functions.php for your domain (see file path above)
  • Right-click and select Edit, or click the Edit link from the menu bar

The PHP file now opens in a new browser tab.

Edit your functions.php then click the Save Changes button (top right).

If something goes wrong with either method:

  • Rename the copy-functions.php you saved earlier back to php
  • Re-upload the functions.php to your web server
  • Choose OK, Replace File, or whatever confirmation prompt you get to overwrite
  • Try to fault-find the issue or get someone with more experience to help

Closing Comments

It’s not difficult to open and edit your functions PHP file, but you must be careful. Only ever add code that you know is safe and accurate. If in doubt, leave it to a professional.

Share on facebook
Share on twitter
Share on email

Subscribe to my newsletter

Subscribers to my newsletter get all the latest news, reviews, advice and gossip in the world of search engines, internet marketing, self-publishing, and North Wales (where I live). You can sign up for my free newsletter by clicking this link.

My Books

I have a range of webmaster related books for sale on Amazon in both Kindle and Paperback formats. WordPress, SEO & Self-Publishing.
On Amazon

My Online Courses

My courses cover a range of webmaster related skills, from learning WordPress itself, to installing an SSL certificate on your site.
On Udemy

Comments

Leave a Comment

Your email address will not be published. Required fields are marked *

Hello, I'm
Andy Williams!

You can get up to 90% off my Online Courses for webmasters, marketers & affiliates (plus a free course on Gutenberg).

Get my newsletter
delivered to your inbox

18748

We respect your privacy

18749