Three Ways To Edit Functions.php In WordPress

5/5

The World's No.1 WooCommerce Plugin

Opening And Editing Functions.php In WordPress Allows You To Do Pretty Much Anything

If you want to get the full potential out of WordPress, opening functions.php is critical.

It’s one PHP file that is always loaded in your WordPress installation which allows you to modify / add to the behaviour of WordPress.

It allows for the execution of PHP script which pretty much enables you to do anything.

Plugins are comprised of a collection of PHP files, so think of it as your own little super light plugin.

In this article I will show you three ways to edit functions.php

  1. Editing it within the WordPress admin dashboard
  2. Editing it with a FTP client (recommended method)
  3. Editing it directly in cPanel

First, A Word Of Caution When Editing Functions.php

You can bring your website down (temporarily) with a poorly written PHP function.

If you misspell something, add a character where it’s not required or try do something that the PHP language doesn’t like, it will cause a critical error.

A critical error will show up on your website as either a 500 error or your website will just be a white screen (of death).

Now, it’s not a long term issue that causes permanent damage, so long as you undo whatever you did to break it.

Once your code is free of PHP errors then your site will return back to normal instantly.

But for this reason, I don’t recommend editing functions.php on your actual website.

WordPress has built in some features which try to prevent you making a critical error, but if you do sneak a critical error in and you can’t access functions.php in other methods then you are stuck with a broken website.

So keep that in mind.

Second, You Should Adhere To WordPress Best Practices

One important thing to keep in mind when editing functions.php is to use a child theme.

child theme absorbs all of the functions of your normal theme, but allows you to make edits which won’t be destroyed when you update your theme.

If you do not use a child theme, any changes you make will be wiped out by a theme update.

If you are unsure how to create a child theme we would recommend you read this article on creating a child theme.

Editing functions.php directly through WordPress Admin Dashboard (not recommended)

Accessing functions.php has it’s risks as outlined earlier in the read, but in short the below image shows you how to access it.

  1. Open up your WordPress admin dashboard and go to Appearance > Theme Editor.
  2. Select the child theme of your active WordPress theme.
  3. Click on the file called Theme Functions.
You can now add snippets to your functions.php file and then click save changes to commit the updates.

Editing functions.php Through A FTP Connection (recommended)

This is the best way to edit functions.php, it’s the safest and most convenient once you’ve got it setup.

To begin, you will need an FTP Client.

I would recommend either FileZilla or WinSCP, both are free.

I would also recommend getting a text editor, I personally use Sublime Text. 

It makes reading and editing your code MUCH easier – this is not required however you can just use Notepad if you want.

1. Connecting To The FTP Client

When you load up your FTP client, it will ask you to add a website.

You will be faced with some fairly standard login credentials (below is an example of WinSCP).

What you enter here will really depend on your host, each hosting provider will have instructions somewhere on the correct credentials to use.

I would recommend typing in **your website hosting provider** FTP Client Details to find yours.

Once you have yours, save the credentials and click login.

If you are successful you will be directed into a hierarchy of folders.

2. Locating Functions.php

Functions.php is always in the same place.

It is present in your parent theme and if you’ve set up one, your child theme.

If you are not using a child theme, please just do it. It will save you many headaches.

So we will assume you’ve setup a child theme for the purpose of this exercise.

Below is the exact directory where you will find it.

your-website-folder > wp-content > themes > your-child-theme > functions.php

There are two variables here, the first one is your-website-folder.

This could have many names, this is the folder where your WordPress installation is found.

To get an idea of whether or not you are looking at the root of your WordPress installation, it should contain similar files and folders to the screenshot below.

The second variable is the name of your child theme, you will have probably set it up so you should know the name of it.

If not, it should be the active theme in your WordPress installation so you can go and check the name of your active theme.

3. Editing Functions PHP

To edit functions.php you can sometimes just double click it depending on what your FTP client has setup by default.

If double clicking does not work you can usually right click and go edit, this might also let you choose your text editor.

Now once your editor opens up with functions.php you simply enter your desired code and click save on the text editor.

This will push the saves into the FTP client.

You should see a dialog box or some sort of confirmation showing that the file was updated.

Editing functions.php through cPanel

Editing functions.php through Cpanel is not a very user friendly way to go about it, but it’s the most accessible.

If you’ve got a web browser and a Cpanel you’re good to go.

1. Jump Into Your cPanel and Go To File Manager

2. Locate The Functions.php Directory As Below

your-website-folder > wp-content > themes > your-child-theme > functions.php

Again, you will need to follow the directory guideline as above, however your root folder name and child theme name will likely be different from mine.

3. Editing functions.php within cPanel

Now that we’ve found functions.php, to edit it we simply click on it and then click edit up on the top bar.

It may bring up a dialog basically asking about encoding, this will likely not effect you so you can just proceed by clicking edit.

The internal editor is not very intuitive so this is far from being the best way to handle things, but can sometimes get you out of a tight spot.

And that’s it, that’s how we edit functions.php in cPanel.

Help! I Broke My Website 🙁

If you broke your website while in functions.php, don’t stress it’s super easy to fix.

I’ve done it a million times, one character in the wrong place and your website is gone.

First of all, I would just undo whatever you just saved before it was broken.

We don’t always know what we did to break it though, so the other thing to do is to delete everything in functions.php except for the beginning <?php and then save.

If your website comes back to life with a blank functions.php then your issue is definitely within this file, if not something else may be wrong (don’t forget to leave the beginning <?php if you want to delete everything!)

Now you simply start pasting your functions back in one by one and saving as you go, checking your website each time you paste a new one in to work out which function is breaking your website.

Once you’ve worked out the culprit function, take a very close look at it and run it through a PHP syntax checker.

If you can’t solve it, just don’t add it back in keep that devilish code away from your website.

That's How To Edit Functions.php In The WordPress Dashboard, An FTP Client And Through cPanel

There we have it, there’s plenty of ways to access functions.php so knock yourself out.

If you have any questions or having troubles accessing functions.php please don’t hesitate to leave a comment below and I will get back to you within a day or so.

Happy coding!

Chris

Subscribe
Notify of
guest
2 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
Jim Wowchuk
Jim Wowchuk
1 month ago

Created my child theme and it worked as expected. Many thanks for doing it in such a safe way.

Itzel Kerr
1 year ago

Great information shared.. really enjoyed reading this post thank you author for sharing this post .. appreciated