Especially as a WordPress beginner, the functions.php file can be quite confusing. There may even be up to 3 of these functions.php files on your WordPress site. In this article, you will learn how to find, open, and edit these files. You will learn everything you need to know about functions.php.
What is functions.php?
The functions.php file controls important parts of your WordPress site. There are usually two functions.php files: one is part of the WordPress installation, and the other is in your WordPress theme. If you are using a child theme, this theme should also have its own functions.php file. The functions.php file is essential for the functionality of your WordPress site. You should avoid touching the functions.php file in the Core WordPress installation as it controls central WordPress functions. The functions.php file in your theme controls theme-specific functions and settings, such as the header and footer, widgets, the length of the post excerpt, and more.
The functions.php file in your theme is somewhat like a plugin. The difference is that the functions.php file of the theme only runs when the theme is activated - it is theme-specific. On the other hand, plugins are used when you want functions to remain even if you change the theme.
Where to find functions.php?
Now that you know what the functions.php file is, let’s find out where to locate it. Here’s the answer.
Where is the functions.php of the Core WordPress installation?
You can find the functions.php file of the WordPress Core installation in the wp-includes folder. But be careful: Keep your hands off it! Only edit this file if you are absolutely sure about the impact of the changes. One possible reason you might need to touch this file is if you suspect malware. In that case, it’s best to involve a developer who knows what to look for. Make a backup of your website in any case.
Where is the functions.php file of the theme?
You can find all your themes in wp-content → themes. If you open the folder of your active theme in this directory, you will find the functions.php file.
Where is the functions.php file of the child theme?
Your child theme is located in the same folder as your other themes (wp-content → themes). The functions.php file can be found in the folder of your child theme.
How to open and edit functions.php?
You now not only know what the functions.php files do, but you are also capable of finding them - great! The only question that remains is this: How can you open and edit the functions.php files? Let’s find out.
How to open and edit the functions.php file of the Core WordPress installation?
To open and edit the functions.php file of the Core WordPress installation, it is recommended to use an FTP/SFTP access to the directory. If you need help with this, consult a developer or contact your hosting provider. Some providers even offer a web-FTP service, where you can view and edit your files directly in the browser.
There are also various plugins that you can install to edit the Core files. However, be sure to check the credibility of the plugin and delete it if you no longer need it.
How to open and edit the functions.php file of the themes and child themes?
For the theme and child theme, opening and editing the functions.php file is a bit easier. You can simply use the Theme File Editor, which is included in WordPress by default. Just open your WordPress admin dashboard (/wp-admin/) and go to Design → Theme File Editor. You will now arrive at the theme editing page.
At the top right, you can select the theme you want to edit. In the right sidebar, you have the option to select functions.php and edit the file.
If you want to edit functions.php of a theme that you didn’t develop yourself, it’s best to create a child theme. This way, you won’t accidentally destroy essential parts of the theme. If you edit the parent theme, WordPress will also give you a warning on this page!
Once you are done with the editing, simply click “Update File” at the bottom.
Editing with a Plugin
There are handy plugins (like Snippets) that make it easy to build custom functionality without having to set up a plugin or child theme yourself. For simple changes or for people with less knowledge in WordPress development, such a plugin can be a good solution.
When should you edit functions.php?
You are now quite the expert on the topic of “functions.php”! You know what the file does, where to find it, and how to open and edit it. But when should you even bother touching the functions.php file? It depends on which file you are dealing with. Let’s go through the important points.
When should you edit the functions.php file of the WordPress Core installation?
The short answer: NEVER! The slightly more detailed answer: Only in the worst-case scenario. It may happen that the functions.php file of your WordPress Core installation becomes infected with malware. In this case, you should make a backup of your site and consult a developer. Additionally, a security plugin can help identify and remove the malware.
When should you edit the functions.php file of the theme?
If you have created the theme yourself, you will probably add a lot of custom code to the functions.php file. Almost all themes have some kind of custom functionality in their functions.php file. If you want to add additional functionality to your site that is not directly related to your theme, then you should probably create a plugin. This way, the function will remain even if you change the theme. Theoretically, you can even upload the plugin to wordpress.org so that other users can benefit from your work. Quick tip: There are countless WordPress plugins available. There’s a good chance that there’s already a plugin that does exactly what you want to achieve. So do a quick search before investing unnecessary time in developing a custom solution.
When should you edit the functions.php file of the child theme?
If you are using another developer’s theme, you should use a child theme to make changes to functions.php. This way, you can ensure that you don’t inadvertently destroy core functionality of the main theme. Additionally, your changes would be overwritten if you update the main theme. In short, a child theme is the safer choice.
Even before editing the functions.php file of the child theme, consider whether it would be better to create a plugin to retain changes if you switch themes.
You now know the most important things about the functions.php file in WordPress! Let me know how you found this article and feel free to message me if you have any questions or issues!)
Need help with your WordPress site?
Feel free to reach out to me! I'll be happy to assist you.Contact now