Include files in child theme functions file

Typically in my theme function file I’ll require other files to keep things neat.

require_once("foo.php");

Now working in a child theme I’d like to do that same. I’m adding custom admin options and it seems impossible to include code. I’ve echoed out the path to make sure I’m calling the right file and it is calling the proper location but nothing inside that file seems to run. The code runs fine if placed inside the child theme functions file.

8 s
8

Child themes reference parent themes by directory name, and in a normal install all your themes live in wp-content/themes/, so I’d say it’s fine to reference those themes by their relative path:

include '../parent-theme/some-file.php';

If that makes you uncomfortable, I observe the following constants in WordPress 3.0.1 with a twentyten child theme called tt-child:

TEMPLATEPATH     /home/adam/public_html/wp3/wp-content/themes/twentyten
STYLESHEETPATH   /home/adam/public_html/wp3/wp-content/themes/tt-child

So you can do the following in your child theme to reference the parent theme directory:

include TEMPLATEPATH . '/some-file.php';

Leave a Comment