How to find the directory of your WordPress Theme in PHP

To get the directory of the current theme (or child theme) you can use get_stylesheet_directory_uri(). Here’s how to use it.

Let’s assume that your WordPress installation lives in http://demo.com, and that your theme is located in a folder named “my-super-theme”. We can assume then that the full URL that points at

http://demo.com/wp-content/themes/my-super-theme/

The URL will of course be different for every user of your theme, so you can’t hard code this. Instead, you can use this handy function:

$myThemeDirectory = get_stylesheet_directory_uri();

This will give you the same URL as above. You can also link to files inside your theme’s directory, for example:

$myImage = get_stylesheet_directory_uri() . '/images/my-super-image.jpg';

get_stylesheet_directory_uri() will point to the directory of your theme or your child theme. If you’re using a child theme and want to explicitly link to the parent theme’s directory, you can use get_template_directory_uri().

From the WordPress Codex: