I’m not sure why you want to use functions.php (note that it’s plural, BTW) for the issue you have, but I guess you know what you’re doing…
Well done for creating a child theme.
First, you add a functions.php file to a child theme by simply creating a file called functions.php in your child theme’s folder. That’s it.
Now, unlike any other files you put in your child theme, your child theme’s version of functions.php gets loaded *before* the equivalent file in the parent. That’s why it’s important to make sure before you go creating a function of the same name that you check that your parent theme’s equivalent function is surrounded with:
if ( ! function_exists( 'function_name' ) ) :
In the case of twentyeleven it almost certainly is as it’s a child-theme-friendly theme.
The upshot of all this is that your child theme’s version of any functions gets loaded first and so the (wrapped) parent theme’s version is ignored.
And that’s it!
HTH
PAE
Here’s how to add a favicon, BTW
PAE
Peredur, I notice you have helped a lot of people on here.
Just wondering if you can help me with something. I see everyone talking about files and there being content in them, can you explain in the simplest of terms where they are???
Thanks heaps, and sorry for hijacking ur post JoAnn22
Peredur, so you don’t think I should use the functions.php file to add additional header photos and a favicon? I know how to add those things to the original functions.php file, but I didn’t think I should be editing the original file. So I’m trying to figure out how to make my own functions.php file for the additions I want to make instead of editing the original file. Do you think I should just edit the original file? I guess I don’t know how to do what I want to do without using the functions.php file. Is there another way?
Well, you certainly don’t need to alter your functions.php file to add a favicon, as the link in my previous post shows.
For your other problem (the images), you might put a function in functions.php, I guess.
As to how to make your own functions.php file, I thought I’d explained that. Is there something in my earlier post (last-but-one) that you don’t understand?
Perhaps I should have made at least one thing clearer. WordPress loads your functions.php file, from your child theme directory, first and then it loads the parent theme’s functions.php file. So you don’t have to copy the parent functions.php file.
Cheers
PAE
Just a thought. On the business with the images have you tried uploading an image from your Dashboard –> Appearance –> Header page?
I’m just wondering if that image then gets added to those supplied by default: and if it does, whether it gets added to the list of those that will be shown at random if you check the random check box.
Just a thought.
Cheers
PAE
Ok, I understand about the favicon, thanks for the very informative link. I do understand what you said about the functions.php I don’t think I’m explaining my question enough. I guess I’m just trying to figure out if I can make my own functions.php and add bits and pieces in it to change or update my theme in the same way I do with the style.css file. For an example, with the random photos used for the header. Can I make my own functions.php file copying the snip-it of coding from Twenty Eleven’s original functions.php file and change it to pick my own photos? And that be the only coding in my functions.php and that way I’m not editing the original functions.php. Or do I have to create a fully complete and extensive functions.php like the original? Does that make sense? If not, I guess I’ll just keep playing until I figure it out. 🙂
And no, to add my image in the list of random images I need to add it to the array in the functions.php file. Like I said, just trying to figure out if I can do that without editing the original file. Thanks for all your help. Even though I’m probably not making much sense. 🙂
Hi JoAnn22,
I’m clearly not being clear.
To have your own functions.php file just create one in your child theme directory.
What you put in it is up to you. You can leave it empty if you want.
Whether you use an existing function from your parent theme as a template for a new function of your own creation or not, is up to you. Whether you overwrite a function in your parent or write a function with a completely new name, is up to you.
But as far as I can tell, you don’t need to mess with a functions.php file to do what you’re trying to do. I just looked at the code in the existing functions.php for the twentyeleven theme and believe from what I see that the random images will be taken from those registered with the theme. I’m also assuming that uploading an image of your own from Dashboard –> Appearance –> Header will register that image. So it will automatically (I think) get included in the images to be picked from. If I’m wrong about this, I’ve no doubt someone else will chip in and say so.
And if that doesn’t work, I’d try uploading an image (of the right size, of course) to wp-content/themes/twentyeleven/images/headers/ and see what happens.
There doesn’t seem any point in writing new PHP code if the existing code will do it for you.
Cheers
PAE
PAE OK I now understand what you are saying, and you did answer my question, thank you! And I have looked, and though I’m not an expert, it doesn’t seem like just uploading a header will include it in the random headers like I want. But I do know the coding to do that, I just didn’t know if I could do partial coding in my own functions.php, which you answered. Thank you for sticking with me on this, it has really been a HUGE help. 🙂
Yes. You’re right about the need for a bit of coding to do it. I just tried it out on my local test site.
In case you hadn’t seen it, here’s some instructions on how to do it:
http://voodoopress.com/2011/07/adding-and-removing-default-headers-in-twentyeleven/
Cheers (and thanks for teaching me something)
PAE
Excellent, those instructions look great. Thank you so much for your help.
De nada. And happy blogging!
Cheers
PAE