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?

| improve this question | | | | |

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.


| improve this answer | | | | |
  • 3
    +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 '14 at 3:41
  • @NoBugs - I was getting the entire server path as well but using get_stylesheet_directory_uri() instead of get_stylesheet_directory() solved the issue. – TheLibzter Feb 4 '15 at 22:19


| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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