WP-Mix

A fresh mix of code snippets and tutorials

Get child or parent theme URI & path

These days, WordPress provides numerous ways to get the path and URI for the current theme directory. This post is reference for WP developers who need to get the URI and/or path for the current child or parent theme. Just grab, gulp, and go..

Theme stylesheet

Get the URI and path of the current theme’s root directory (parent or child, whichever one is active):

get_stylesheet_directory()     // PATH (parent or child)
get_stylesheet_directory_uri() // URI (parent or child, checks for SSL)

Usage:

<?php include(get_stylesheet_directory() .'/example.php'); ?>
<img src="<?php echo get_stylesheet_directory_uri(); ?>/example.png">

Theme Directory

Get the URI and path of the current parent theme’s directory (parent theme only, does not get child theme directory):

get_template_directory()     // PATH (parent only)
get_template_directory_uri() // URI (parent only, checks for SSL)

Usage:

<?php include(get_template_directory() .'/example.php'); ?>
<img src="<?php echo get_template_directory_uri(); ?>/example.png">

More infos: Include files from parent directory, subdirectory

References

Learn more

Digging Into WordPressWordPress Themes In DepthWizard’s SQL Recipes for WordPress