Forum Replies Created
-
Hello guys.
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’sstyle.css
we must import it using@import url(../parent-theme-folder/style.css);
That’s why
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:
define('THEME_PREFIX_PATH',bloginfo('template_directory'));
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.