1. get_template()
- Purpose: Returns the directory of the parent theme.
- Use case: When you want to reference files from the parent theme, even if a child theme is active.
- Behavior:
- Ignores the child theme.
- Always points to the parent theme folder.
Example:
echo get_template();
// Output: my-parent-theme
If your parent theme folder is my-parent-theme, it will return that regardless of a child theme being used.
You can use it like:
require get_template_directory() . '/inc/functions.php';
Note:
get_template_directory()returns the full path (/var/www/html/wp-content/themes/my-parent-theme), whileget_template()returns only the folder name (my-parent-theme).
2. get_stylesheet()
- Purpose: Returns the directory of the active theme’s stylesheet.
- Use case: When you want to reference files that could be in a child theme, falling back to the parent theme if no child exists.
- Behavior:
- Points to child theme folder if a child theme is active.
- Otherwise, points to parent theme folder.
Example:
echo get_stylesheet();
// Output: my-child-theme
If your active theme is a child theme my-child-theme, it returns that.
You can use it like:
require get_stylesheet_directory() . '/custom-functions.php';
Note:
get_stylesheet_directory()returns the full path,get_stylesheet()returns just the folder name.
✅ Key Difference
| Function | Returns Child Theme? | Returns Parent Theme? | Notes |
|---|---|---|---|
get_template() | ❌ No | ✅ Yes | Always parent theme folder |
get_stylesheet() | ✅ Yes (if exists) | ✅ Fallback | Child theme folder if exists, else parent |
Rule of Thumb:
- Use
get_template()when you always want parent theme files. - Use
get_stylesheet()when you want files from the active theme (child if available).
