Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Kevin Korte
28,149 PointsWP hooks in Child Themes
I'm curious as to how wordpress handles this. I haven't found my answer in the Codex yet. My question is this: I know for instance wp_head is a widely supported action hook that a lot of plugins might use. There are others, like wp_footer. If you are building a child theme, do these hooks get included from the parent theme?
I assume if I have a header.php file in my child theme and do not include the wp_head hook in that file, My child theme will just not have that hook. Correct?
But lets say my child theme does not have a header.php file, and the parent theme's header.php file does have the wp_head hook, does my child theme inherit the wp_head hook from the parent theme header.php file?
Does the same apply for the other hooks, in the other files?
9 Answers
Randy Hoyt
Treehouse Guest TeacherIf you create a template file in your theme, then WordPress will use your template file instead of the parent theme's template file. In your case, if you create a header.php file, then WordPress won't use the parent theme's template file at all. You'll have to include wp_head in your header.php file.
Does that make sense?
Kevin Korte
28,149 PointsThanks Randy! It does, and I was pretty sure it worked that way. And so the opposite would be true. If I did not include a certain template theme file, then wordpress will default to the parent's theme file, and include any hooks that are in that file?
Randy Hoyt
Treehouse Guest TeacherPrecisely! ;-D
Kevin Korte
28,149 PointsSweet! Thank you again!!
Zac Gordon
Treehouse Guest TeacherOh Randy Hoyt , you're so smart!
And great question Kevin, that's some fundamental Child Theme Development learning right there :)
Kevin Korte
28,149 PointsI had that question because I caught up on your building a wordpress theme course you have started, and it got me thinking. I had no idea Wordpress could be so flexible, and I think it'll work well for two different projects I have, so what I'm playing with now is whether to build a complete custom theme, or a child theme.
I think I'm going to build both and see what I like. I've decided to start with building a child theme.
I am excited to see the rest of that lesson released. I think that'll help me decide. In the meantime, I'm practicing locally, and getting as many mistakes in developing made and out of the way as possible.
Great job so far on these. This lesson with Randy's php makes a lot of "ahh hah!" moments.
Zac Gordon
Treehouse Guest TeacherIf you're following along with the video for creating a theme from scratch, I definitely recommend working on a child theme, possibly for the TwentyTwelve theme. Whenever you're working with a pre-made template you're going to want to build child themes anyways since it allows you to update your theme without messing up your customizations.
Great extra effort Kevin!
Kevin Korte
28,149 PointsI think that's good advice. I already learned why child themes are the only way to go when building off an existing theme. Which is what stemmed this question originally, because I wanted to do my best to put back any hooks my child theme was overriding so I didn't have potential issues with updates or new plugin installations down the road.
One day I do want to tackle a full theme development from scratch, even if for just "fun". :)
Zac Gordon
Treehouse Guest TeacherOh very cool to see where you are at with this all! Yes, you'll definitely get to a from scratch one, although starting from some frame working or template (I like TwentyTwelve) is possibly more common.
You might want to start with copying the parent template then editing what you need, if you're not doing that already.