Play along with:
echo '<ul><li>'.implode('</li><li>', str_replace(str_replace('\\', '/', ABSPATH).'wp-content/', '', array_slice(str_replace('\\', '/', get_included_files()), (array_search(str_replace('\\', '/', ABSPATH).'wp-includes/template-loader.php', str_replace('\\', '/', get_included_files())) + 1)))).'</li></ul>';
How do you find out which template page is serving the current page?
admin-bar stuff path is showing at the top, or any other file, change the filename
template-loader.php in this line of code to: whatever filname you need to break from.
if you need this in the admin bar, use the right priotity (earliest) to make shure no files are entered at the end of this list. For example:
add_action('admin_bar_menu', 'my_adminbar_template_monitor', -5);
-5 make shure it loads first. The key is to render this line at the right moment.
It does not returning the "current" template-file, but all the current in use for the current page-load. Maybe "cut out" with some logic from that idea.
get_included_files() "last" key is the last registered included file, propably the last template-file/ -part used in the footer by sidebar widget or something. Propably, cos mutiple included files does not re-register/ populates again in get_included_files().
Otherwise, the intension must be clear to hack this problem. There is no way for a included file to report itself as included, until it has been included. Then its propably to late to use the scenario.
Most of the "time" you would like:
$template = get_current_loaded_template();
if($template == 'single-product.php') add_filter('the_title' ....
if($template == 'format-gallery.php') add_action('post_thumbnail' ....
But thats not possible if the template is loaded outside Wordpress core method of
get_template_part. Re-design your needs instead! Maybe
add_action('the_post') has the solution you want, to alter data depending of template thats gonna load for each entry within a loop.