ACCESSING THE CURRENT THEME’S PATH IN WORDPRESS
To access the cureent theme’s path is not difficult. What you’re looking for is get stylesheet_directory_uri. With this simple function the current theme’s URL can be retrieved.
For example:
<img src="<?php echo get_stylesheet_directory_uri(); ?>/assets/myphoto.jpeg" />
The get_template_directory(); will return to the parent theme if you are using a child theme. On the other hand, get_stylesheet_directory(); will go to the current theme, child or parent. These techniques are guaranteed to return server paths.
Methods To Use:
- Get_stylesheet_directory
Folder path of current theme
e.g. /var/www/sitename.com/wp-content/themes/child_theme
- get_template_directory
Folder path of parent theme
e.g. /var/www/sitnename.com/wp-content/themes/parent_theme
- get_stylesheet_directory_uri
Full URL of current theme
e.g. https://sitename.com/wp-content/themes/child_theme
- Get_template_directory_uri
Full URL of parent theme
e.g. https://sitename.com/wp-content/themes/parent_theme