Functions files and child themes – explained !
Creating a child theme and functions file
Many wordpress and bbpress support answers tell you to add some code to either your functions file, or your style.cc But what is a functions file and what is a style.css file – how do I create them and where do I put them?
This tutorial hoped to answer all these questions and more !
What is a functions file?
A functions file is simply a file called Functions.php which sits in your theme. This lets you add additional functions to wordpress and bbpress without needing to alter the code within those files. If you change code within bbpress and wordpress it is likely to get overwritten on any updates, and you will lose it.
Now since the functions file belongs to the theme, it is equally likely that it will get overwritten on a theme upgrade, so for these reasons, the best course of action is to create a child theme (if you don’t have one already), and put a functions file within that.
What is a Style.css file?
Every theme has a style.css, but plugins can also add additional style files. Together these files determine how your page looks, for example where on a page an element may sit, whether it has any padding to keep it apart from other text, what font, color and size your text should be, styles for your various headings etc. A style file can also hide things, so occasionally we might suggest that you change an element to ‘display:none’ so that it gets hidden. Like functions files, style files can be overwritten by theme or plugin upgrades, so changing these for a theme or plugin hat you have not written yourself is not recommended. So like with the functions file, the best course of action is to create a child theme (if you don’t have one already), and as aprt fo this you will have a style.css fort that theme.
Do I have a Child theme already?
So firstly we need to see what your theme is, and whether is a parent or child theme. If it is a parent theme then you should create a child theme, add a functions file to that child theme and put your changes in there. If you change any files in parent themes, you may lose the changes on an update or upgrade. So you don’t want to change parent theme files.
Your wordpress theme
First of all your wordpress installation will be using a ‘theme’ – this is a collection of files that styles your site (how it looks) and adds some functionality (how it acts).
You might be using one of the ‘default themes’ twenty-ten, twenty-eleven, twenty-twelve, twenty-thirteen and twenty-fourteen. These themes are written and maintained by the wordpress team, and all wordpress and bbpress code is tested against these themes to ensure it works. This is why you will often be asked to test an issue with bbpress using a ‘default theme’, as part of the investigation process.
Alternately you might be using a ‘free theme’. Many of these are available at https://wordpress.org/themes/ .
Thirdly you may be using a paid for theme. These tend to be more complex and offer lots of goodies, but integration with bbpress can be more complex. It worth checking if your paid for theme actively supports bbpress before buying if bbpress is important to your site. Most themes can be made to work with bbPress with a few tweaks, but it can be really frustrating initially getting it going and looking great.
Finally you may be using a child theme. Quite simply this is a theme which uses one of the above (default theme, free theme or purchased theme) as it’s base, and then has alterations done. If you have paid someone to create or customise a site for you, there is a good chance that it might be a child theme.
So how do you know which you are using?
The quickest way is to go into
You will see a list of themes installed on your site, and you will see that the first listed is ‘active’ and that is the theme your site is using.
If you hover over the active theme it will display ‘theme details’ and if you click that you will get some information about the theme.
If it is by ‘the wordpress team’ then you’ll know it is a default theme. Otherwise go into https://wordpress.org/themes/ and search for it. If it is there then it is a free theme. Finally if you google the theme name you should come up with a seller, or at least some support details that will tell you someone else has written this theme.
If any of those show then you have a parent theme that is being supported elsewhere, and they may issue updates, so if you change any files in these, you may lose the changes on an update or upgrade. So you don’t want to change these files.
If you failed to find your theme by any of the methods above, or if you know that someone altered a theme specifically for you, then chances are that this is a child theme, so it should not be updated by anyone external, so you should be able to make changes without worrying.
So one final test to check if your theme is already a child theme, and we’ll ready to proceed. So now you’ll need to be able to go into FTP, and transfer a file to your PC, so that you can them look at it to read the heading.
What is FTP and how do I access it?
To access your files, you’ll need an FTP client. Some host providers do with within their administration area, check with your host provider if in doubt.
Otherwise you’ll need to load a program onto your PC. Several are available, but one of the most popular is called “Filezilla”.
To learn how to download this programme and use it on your PC, the following video will help
There are lots of other tutorials out there – just google “filezilla tutorial video”
Other FTP programmes are also available, just google “FTP client”
To get access to your web files, you’ll need three pieces of information:
Note: the FTP username and password are entirely separate from your wordpress login/wp-admin/admin details.
Your host provider will usually list this in your administration area, so just look around for FTP, and if in doubt, contact your host provider.
Then follow the tutorial
If your theme imports another theme as shown in step 2, then you already have a child theme.
If not, the above tutorial will show you how to make one.
By the end you’ll have a child theme with a style.css file
Changing code using notepad++
Since you’re going to be creating or altering files, then you’ll need someone to do this with. Plain notepad can be used, but mostly what you’ll have is unreadable, and you’ll make a mess.
So download Notepad++ from http://notepad-plus-plus.org/
It’s easy to use and so much better !
Adding a functions file to your child theme
If you already have a child theme, then chances are you already have a functions file, just look for a file called functions.php in you theme folder.
If not you’ll need to create a functions file.
Just open up notepad ++, create a new file and put
at the start. Now save it as functions.php and upload it to you theme. And that’s it. You now have a functions file !
Adding code to a functions file
Ok so now when you see ‘add this to your functions file’ , you’ll know that you need to download you current functions file to your PC using FTP. Then using notepad++ copy the code onto the end of your functions file. Then upload the amended file back to your site using FTP to overwrite the old file.
Adding styling to a style.css
As you now have a style.css as an integral part of your child theme, you can add any changes to this file.
And that’s it… !!