Referencing directories in WordPress themes

I needed to enqueue a handful of scripts and stylesheets in a WordPress theme and ran into much confusion between which functions to use to return what paths from the parent theme vs. the child theme. To save myself later here is the breakdown of when to use what. Basic gist is that “stylesheet” will get the child theme. “template” will get the parent.

If you don’t have a child theme any of these will get the current theme.

Absolute Path

These functions get the absolute path on the server’s file system. Mostly useful for referencing other PHP files within your theme’s PHP files:

get_stylesheet_directory() – absolute path to the current theme. If you’re using a child theme it’ll get it. Documentation.

get_template_directory() – absolute path to the parent theme. Even if you’re using a child theme it’ll get the parent. Documentation.

Directory

These functions get the public URI for the theme directory. Useful when you’re trying to publicly display something on the site through your theme files:

get_stylesheet_directory_uri() – returns a properly formatted URI for the current theme. Use if you have a child theme that you want to return. Documentation.

get_template_directory_uri() – returns a properly formatted URI for the parent theme. Even if you’re using a child theme it’ll get the parent theme. Documentation.