How to add functions php file in wodpress child theme

How do you add functions php file in WodPress child theme?

Do you get error when you try to add functions php file which is copied from a parent theme into its child theme?

Its obvious that we don’t understand things at first place. Before understanding – we jump into doing things and suffer later. But, believe me – adding a functions.php file in a child theme isn’t that hectic as you think.

It’s very simple – If you have knowledge on PHP, then, you might figure out much faster than I did or most of you might do!

But, no worries – I’ll take you through the process and add functions php file into your child theme without causing an error. That’s my promise!!

Getting you started with the process:

Hope by this time you should have a WordPress website up and running with a Child theme in it. Other wise you wouldn’t have come here right?

Ok, Great!

Step1: First go into your parent theme and copy functions.php and paste it inside of your child theme.

Step2: Open the functions.php inside the child theme with a HTML editor. Preferably Notepad++ which is quite fast.

Step3: Delete all the contents inside the functions.php file except ‘<?php‘ at the top of the file and please, do not add the ‘?>’ at the end of the file that’s not needed.

According to WordPress you cannot just replicate a function that is already present in the parent functions.php file. Functions are referred only once. It can’t be everywhere.

That was the reason why I asked you to delete all the contents in there!

There was a setup function hanging on top of the parent functions.php file which is very important to run your functions. But, that’s not needed again here in the child theme.

Both child theme file and parent theme file will be parsed when WordPress process functions but, in an order. Child theme file is parsed first then the parent theme file. So the setup function will be referred from the parent theme.

Only inner function will be parsed from the child theme.

So, what next?

Now, you are good to add you new or custom functions to the functions.php file. Your functions.php file will look like this before you add any functions to it.

WordPress child theme - functions

PHP

1

<?php

You can add any functions that are available on WordPress.org or write your own. I’ll take an example function and show you how to add it to the functions.php file in your child theme.

About Sumesh M.S

I'm a Web developer (Front End). I love to explore and learn new techniques around the Web and write them here in a simpler manner for other users who find them tough. You can also Follow me on Twitter, Google+ and Facebook