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

JavaScript

Entire Wordpress site disappears when adding child theme functions.php

I'm currently developing a child theme for the Twenty Twelve with some relatively basic changes: reorganizing the banner/nav layout in the header, applying some custom styles, etc.

The most important change, however, is adding a dynamic jQuery slider into the mix. I'm following along with this WPTuts tutorial, which has been fine thus far, except... once I go and add this code to the child theme's functions.php:

<?php

   // Create slider post type
   require(get_template_directory() . '/inc/slider/slider_post_type.php');

   // Create slider
   require(get_template_directory() . '/inc/slider/slider.php');

My entire Wordpress site disappears. The admin bar, the posts, html, everything. It simply displays a blank white page. Cutting the code out of the functions.php, saving, and refreshing the page restores everything to order.

So my question to you is, what rookie mistake have I made here?

10 Answers

Is this the only code in your child's functions.php theme?

Wordpress treats the function.php file differently than any other theme file.

A child's function.php theme does not override the parent functions.php theme. It's loaded in addition too, and specifically right before the parent's function.php file is loaded.

Loading a duplicate pf the parent's function.php file in the child theme will cause the page to go all blank.

Is that what might be going on?

Hi Kevin Korte , thanks for chiming in. Yes, this is the only code in the child's functions.php. I also checked it for extra line breaks (which I understand can cause issues in PHP), and experimented with including and excluding the PHP closing tag (which didn't make a difference).

I had read the WP documentation about child themes, so I knew that it adds to the parent theme's functions.php, rather than replace.

The only other difference I can see here, which shouldn't conceivably make a difference, is that this tutorial seems to be dealing with a parent theme rather than a child theme, but that shouldn't matter, right?

I don't know for sure on the parent theme vs child theme question with the function.php file; that's a good one.

I'm sure Zac Gordon could tell us.

You've done all the basics that I know of. In your code you posted you do have white lines between the opening php tag, and between the requires. Have you tried completely removing every white line space to see if that changes it?

Kevin Korte ,

I gave that a shot, but no dice.

I went back and looked at the instructions for adding the code to the function.php to see if perhaps I had done something wrong. I noticed that the code it told me to add didn't include the opening functioning php tag, which I figure is because it was telling me to add it to the parent functions.php, which would have already included the opening tag. I tried removing it, to see if that changed anything...

The site came back, of course, but it just spit out the php function and comments at the top of the page as HTML. And that's not what we want, either.

Zac Gordon
STAFF
Zac Gordon
Treehouse Guest Teacher

Try using http://codex.wordpress.org/Function_Reference/get_stylesheet_directory instead of template directory

With child themes the template directory links to the parent and stylshheet URL to child

Zac Gordon ,

Thank you so much! That did the trick. I will remember that for the future.

Ha, something simple! Figured it was....I just wasn't too sure.

It's always the simple things. :)

Yep, they are all so easy to over look too!

I'll be running into this pretty shortly as I'm working on a child theme myself on the side. Haven't got to the functions.php file yet, but I will, so this will come in handy.

Zac Gordon
STAFF
Zac Gordon
Treehouse Guest Teacher

Oh good! Yes, nice little theme developer secret there ;)