Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

This code is used to get the directory of the current plugin: plugin_dir_url( __FILE__ ).

What should I use to get the directory of the current theme?

share|improve this question

2 Answers 2

up vote 13 down vote accepted

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

share|improve this answer
1  
+1. Always use stylesheet filepath/url to reference the current Theme, and reserve template filepath/url to reference the parent Theme. –  Chip Bennett Apr 5 '12 at 21:00
    
Unfortunately get_template_directory() returns the entire server path like /var/www/the/path/of/actual/wp-content/themes/mytheme which is not what you want for doing stuff with $wp_filesystem if WP is connecting through FTP. –  NoBugs Sep 11 at 3:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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