get_template_directory vs get_stylesheet_directory

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

In this post, it states

Read More

'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()?

Related posts

1 comment

  1. 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).

Comments are closed.