4

I am trying to create a child theme and need to replace some files that are in sub-folders.

In this post, it states

'get_stylesheet_directory(); will go to the current theme, child or parent

Why don't theme developers just use get_stylesheet_directory() if it would work for the parent or child theme?

It seems that I now have to change every reference to get_template_directory() to get my child files to work (that are in sub-folders) or is there another way of doing this?

This post by Andrew Nacin states that,

you can just replace files directly in a child theme.

But it seems that this only works for one level deep.

Is there a way for this to work with more than one level and would this be easier than changing each reference to get_template_directory()?

1
  • the two things are unrelated, the post you linked to is about the code that WordPress uses to search for custom page templates in a theme. get_stylesheet_directory just contains the path to the active theme, the rest of the path is up to you, so files can be replaced 100 directories deep if necessary.
    – Milo
    Sep 16, 2013 at 0:54

1 Answer 1

4

Why don't theme developers just use get_stylesheet_directory if it would work for the parent or child theme?

The answer is not complicated: "Because you may not want it to work for either the parent or a child theme."

You choose the function that fits the situation. For example, you have a set of files in the parent theme that contain critical classes or functions. You use get_template_directory() because you don't want to allow the child to override/replace the files. It is the same reason you can't replace WordPress Core files or functions (in most cases).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.