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:





Jay is the CEO and founder of WP Hosting, a boutique style managed WordPress hosting and support service. He has been working with Plesk since version 9 and is a qualified Parallels Automation Professional. In his spare time he likes to develop iOS apps and WordPress plugins, or draw on tablet devices. He blogs about his coding journey at http://wpguru.co.uk and http://pinkstone.co.uk.