I think you have to be a little careful because it depends on what you are trying to do.
If you are using a child theme get_template_directory();
will still go to the parent theme. However get_stylesheet_directory();
will go to the current theme, child, or parent. Also, both these functions return absolute server paths.
If you wanted a fully formed URI, for links or images, you should use get_template_directory_uri();
or get_stylesheet_directory_uri();
using the correct one for the reasons stated.
Summary
get_stylesheet_directory()
absolute folder path of current theme
e.g. /var/www/yoursite/wp-content/themes/child_theme
get_template_directory()
absolute folder path of parent theme
e.g. /var/www/yoursite/wp-content/themes/parent_theme
get_stylesheet_directory_uri()
full URL of current theme
e.g. https://example.com/wp-content/themes/child_theme
get_template_directory_uri()
full URL of parent theme
e.g. https://example.com/wp-content/themes/parent_theme
Hello Friends, I’m Mohit Sharma founder of tutrialwala.com, Full Stack Web Developer. Expertise in WordPress, PHP, Laravel, Angular, and Frontend Development. In this publication, I share everything I know about PHP frameworks and Javascript frameworks, packages, and tools.
Have a project in mind? Get in touch