Help with Child Theme
I am very interested into customizing my BP install using the “child theme” paradigm, and I am on my way. One simple question I have for this involves the file structure.
Specifically, when I use the code
TEMPLATEPATHI am given the parent theme’s path. In the past I have also used
get_template_directory_uri()but this yields the same result.
Is there any other defined variable I can use to get the path of my “child theme?” Specifically I assume this is possible without having to hard-code my child themes’ name, since there is an images folder in the sample folder.
use locate_template() —
Thanks Andy, that works great for my extra template files. Maybe I am missing something, but if I want to print the child template directory url for, say an image:
<img src="<?php bloginfo('template_directory'); ?>/images/upgrade-cta.png" />Uses the parent theme directory.
What should I use to replace
<?php bloginfo('template_directory'); ?>with?
<?php bloginfo('stylesheet_directory'); ?>
Check wp-includes/theme.php for lots of little gems like this too.
I had to use this:
<?php bloginfo(‘stylesheet_directory’); ?>
to reach my child theme /js/ folder. It works, but it feels wrong. Is there nothing like bloginfo(‘child_theme’) that makes more sense, won’t get me confused the next time?
Nope. But there are lots of other parameters that template tag will accept:
I prefer using this one, not sure why though.
Xevo, that now points to bp-sn-parent, not the child theme.
I don’t use the parent/child structure, so don’t have any problems with it.
Does anyone else know/care? I get the same problem with TEMPLATEPATH.
I can’t make any sense of the information on Function Reference/locate template.
I need something that works in includes. Like this, but for the child template folder:
<? include TEMPLATEPATH.'/directories/members/featured.php'; ?>
bloginfo() doesn’t work there.
Again, this sort of works:
<? include get_bloginfo('stylesheet_directory').'/directories/members/featured.php'; ?>
But that’s just awkward. Is there really no template tag for the child theme folder?
Aha! Yeah, tell it to look in the template_directory . that pulls the *activated* theme. Which shoudl be the child theme.
….tell it to look in the template_directory . that pulls the *activated* theme. Which should be the child theme.
It doesn’t. template_directory pulls the parent.
I answered this above. No. There is no parameter for the template tag bloginfo() called “child_theme_directory” or anything similar. To write in the child theme directory, use “stylesheet_directory”. That works. For a full list of parameters that this tag will accept, please read the manual. They’re all listed under the header “Parameters”:
p.s. Looking at the codex page above, I see there is a parameter call template_url. No idea of that will write in the parent or child dir. But it’s one you haven’t tried I think.
I can live with get_bloginfo(‘stylesheet_directory’) if that’s the way to do it. It’s just not as straightforward as TEMPLATEPATH, could cause confusion later on.
I know about bloginfo parameters. What kind of thingy is TEMPLATEPATH? Where is it defined? Could I create a CHILDTEMPLATE somewhere?
I’m still trying to wrap my head around the new parent/child structure…
The constant TEMPLATEPATH is a reference to the absolute path to the template directory for the current Theme. I don’t know how it behaves with parent / child themes but it sounds like, from your experimenting, that it points to the parent. Which makes sense. The parent theme IS the theme as far as the system is concerned. The child is just along for the ride. It’s just hooked to the parent via the style.css file.
The syntax you have above is correct.
<? include TEMPLATEPATH.'/directories/members/featured.php'; ?>
And there are no parameters for TEMPLATEPATH. It’s just a constant. Anyway, if stylesheet_directory works… may as well just go with that.
Parent / Child is pretty simple. A child theme can be as simple as a single style.css file with a link to another theme (it’s parent) in the comment section at the top of the file. i.e.:
Done. Now you can make your own styles to override the parent styles. And additionally… as you probably know… you can override any parent template file by placing a template file of the same name (and location) in the child theme. That’s about it.
And I would assume that any wordpress functions / constants / etc. that refer to template locations (other than the blog_info(‘stylesheet_directory’) will refer to the parent.
I see that STYLESHEETPATH is the equivalent for TEMPLATEPATH to the child theme.
I’ve just started developing a child theme for a theme I’m almost finishing developing and I got frustrated with this same behavior.
I will try to explain it better. As I’ve noted, WordPress doesn’t see the child theme as the actual theme, so
bloginfo('template_directory')will return the parent theme.
BUT, if you faced this situation you already know that the sole unique parent theme’s file that is not inherited by child themes is
style.css, which is the only file a child theme is needed to have. If we want to use parent theme’s
style.csswe must import it using
bloginfo('stylesheet_directory')returns the child theme path. As a record, template_url also refers to the parent theme.
I’m not sure of that, but I believe we can nest themes on a list, having THEME-1 as the root, THEME-2 as its child implementing some new extra stuff and THEME-3 having THEME-2 as its parent and adding a few more features. That’s not as impossible to happen as some may thing, I’ve already seen a few Thematic’s child themes, and if you wanna use any of them and do a few changes to their CSS, having 2 nested child themes is really possible, if WordPress supports it of course.
And with that we may end up with a now real problem: template_directory points to top parent theme, and stylesheet_directory points to the bottom child theme… Probably middle child themes will break when they try to access their files using stylesheet_directory and they are not found…
WordPress really needs to solve this, they should implement something like
templatedir('theme-name'), where we can access any theme we want, even classic and basic…
For now what I’m gonna do is use PHP constants. My parent theme already has its:
And for my child themes I’ll do the same using stylesheet_directory. Doing so, if someday WordPress gives a final solution for this mess, we’ll just have to use it on this constant and all our child themes will be fixed.
It’s sad but seems to be the most maintainable solution I’ve found.
- The topic ‘Help with Child Theme’ is closed to new replies.