get_template_directory vs get_stylesheet_directory

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

Leave a Comment

tech