Using WordPress ‘get_stylesheet_directory()’ PHP function

The get_stylesheet_directory() WordPress PHP function retrieves the stylesheet directory path for the active theme.

Usage

include( get_stylesheet_directory() . '/includes/myfile.php' );

Parameters

  • None

More information

See WordPress Developer Resources: get_stylesheet_directory()

You can also use the constant STYLESHEETPATH in replacement of get_stylesheet_directory(). However, using the function is preferable, as it includes additional logic and filter options.

get_stylesheet_directory() retrieves the child theme’s directory. To retrieve the parent theme’s directory, use get_template_directory() or locate_template().

Examples

Include a custom CSS file

Load a custom CSS file named custom-styles.css from your theme’s stylesheet directory:

wp_enqueue_style('custom-styles', get_stylesheet_directory_uri() . '/custom-styles.css');

Include a custom JavaScript file

Load a custom JavaScript file named custom-scripts.js from your theme’s stylesheet directory:

wp_enqueue_script('custom-scripts', get_stylesheet_directory_uri() . '/custom-scripts.js');

Include a PHP file from a child theme

Load a PHP file named extra-functions.php from your child theme’s stylesheet directory:

include( get_stylesheet_directory() . '/extra-functions.php' );

Display an image from the active theme’s directory

Display an image named logo.png from your active theme’s stylesheet directory:

echo '<img src="' . get_stylesheet_directory_uri() . '/images/logo.png" alt="Logo">';

Load a custom font file

Load a custom font file named custom-font.woff2 from your theme’s stylesheet directory:

@font-face {
  font-family: 'CustomFont';
  src: url('<?php echo get_stylesheet_directory_uri(); ?>/fonts/custom-font.woff2') format('woff2');
}