Often you want to change a small thing in your theme, add new features or change existing ones. In the net you can find lots of tutorials, which should make these projects possible. Then it is not seldom: “insert this snippet into the functions.php of your themes and done! Yes, if only it were that simple. Because not too seldom exactly this leads to a complete website failure. The functions.php file is a sensitive one and if you insert the code somewhere without any knowledge, you risk to paralyze the whole website. In this tutorial I will show you how to edit the functions.php of your WordPress theme correctly without shutting down your website.
How can I edit the functions.php of my theme?
There are two main methods to edit the files of your theme. As so often, the convenient method is not the best way to make changes. In the following I will go into more detail about the two methods.
Changes to the PHP via WordPress Code Editor
The convenient method, which I expressly do not recommend, is to edit files using the WordPress Editor. You can find the source code under Design > Editor. Then you have to select the theme you want to edit. The available files are listed on the right side.
In the list you will find the template (php) and stylesheet (CSS) files of your theme. While changes to the CSS usually do not lead to any complications and in the worst case the design is moved a bit, changes to the PHP files can paralyze the whole website. Therefore this method should not be used for experiments and changes should only be made if you are totally sure about what you are doing.
Make changes to the PHP via FTP
The better and more secure solution is to use an FTP (File Transfer Protocol) client. Anyone who has installed WordPress manually, and not via 1-Click Installation, will be familiar with FTP transfer. If you haven’t had any experience with data transfer via FTP, you can find everything else in our FTP Tutorial.
Instructions: Edit the theme functions.php correctly
First we establish a connection between our FTP client and the web hosting server. Then we search our webhosting server for the file we want to edit in the right field of FileZilla. If you want to edit the functions.php you can find it at: /wp-content/themes/*your-theme*/functions.php.
A backup should be made before the file is edited. To do this, we define a storage location (e.g. desktop or USB stick) for the backup in the left area of the client, right-click on the file to be backed up and select Download.
We use the downloaded file as a backup in case something goes wrong during editing and we need to restore the file. Then we right-click on our backup copy and rename it (e.g. copy functions.php). Now we download the “original” functions.php again. After that it should look like the following screenshot:
The file can then be edited. To do this, we open the document with a right click (not a double click). After opening it, the desired changes can be made. For this you should use a simple word processing program. On a Mac, TextEdit is a good choice. Windows users can use Notepad. If you don’t have both programs, you can download the free word processor Atom. If you don’t know where to put the code, the following article will help you: Include code correctly in the functions.php theme
Once all changes have been entered, the file must be saved. Then we click again with the right mouse button on the file and select Upload.
FileZilla will now tell you that a file with the same name already exists. Select Overwrite to replace the original file with the changed version.
Once the modified version has been uploaded to the server, check the functionality of the website. Except for your change, everything should be as it was before. Is everything okay? Then that’s it!
If your website shows a white screen or an error message, then something went wrong. Maybe you put the code in the wrong place?
help with white screen or error message
Good thing we backed up. If you didn’t do that because you thought it would work out, we have a (more complex) solution for you as well.
Try to bring the code back to the original format or paste your code in the right place and check your WordPress website again for functionality. If that doesn’t work, rename the backup copy with the original file name (functions.php). Upload the version to your server and overwrite the changed version. The error should be fixed now.
Re-download the theme you are using. If you use a free WordPress theme, you can download it here: WordPress Themes. Find the functions.php of the theme. Upload it to the server and overwrite the changes. The bug should be fixed now.
More questions? Suggestions for improvement or suggestions for further articles? Then write it in the comments.