Show template file name in wordpress

Created at 18-Mar-2021 , By samar

Show template file name in wordpress

In this article, we will see how to solve "Show template file name in wordpress".

  • --PATH wp-content\themes\<yourTheme>\functions.php
    add_action('wp_head', 'show_template');
    function show_template() {
        global $template;
        echo basename($template);
    }
    
    If you want to know your current working template file name in wordpress you can see it using this code snippet. Just copy paste this code snippet in your functions.php, it will display the current working template file name. Using this code snippet you can know which template file in your theme is actually being used on a specific page.
  • --PATH wp-content\themes\<yourTheme>\footer.php
    <?php global $template; echo basename($template); ?>
    
    You can just use it directly in the template file (footer.php or header.php) at any place to view your template file name.

Back to code snippet queries related wordpress

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Buy Me A Coffee

Don't forget to share this article! Help us spread the word by clicking the share button below.

We appreciate your support and are committed to providing you valuable and informative content.

We are thankful for your never ending support.