Sage - Show Current Template file

Hi everyone,

I’m trying to show the current template file or what template file is being used.

I tried this one:

add_action('wp_body_open', function () {
    global $template;
    if( current_user_can('administrator') ) {
        echo '<!-- Template File: ' . basename($template) . ' -->';
    }
});

But it always shows index.php

I also tried other plugins that will show the current template file but sadly it always returns to index.php

Does anyone know how to solve this issue?
Thank you

What is the reason you need to know the current template file?

Good morning sir @alwaysblank , thank you for your reply :slight_smile:

My reason is to easily navigate which file is being used or what blade is being used on every pages or posts, especially when you created a lot of custom templates and custom post types. And this is useful for a large development.

This topic was automatically closed after 42 days. New replies are no longer allowed.