• Resolved dragonsjaw

    (@dragonsjaw)


    I used this code in functions on my TwentyTen child sites to show (in the source code) which template was being used.
    I just tried this with my TwentyTwelve child theme, and no luck. ?? Any chance anyone here know what to change to make it work in Twenty Twelve?

    It is very handy.

    add_filter( 'template_include', 'var_template_include', 1000 );
    function var_template_include( $t ){
         $GLOBALS['current_theme_template'] = basename($t);
         return $t;
    }
    
    function get_current_template( $echo = false ) {
         if( !isset( $GLOBALS['current_theme_template'] ) )
             return false;
         if( $echo )
             echo $GLOBALS['current_theme_template'];
         else
             return $GLOBALS['current_theme_template'];
    }
Viewing 5 replies - 1 through 5 (of 5 total)
  • I used this code in functions on my TwentyTen child sites to show (in the source code) which template was being used

    Why? WordPress core already outputs a class on the <body> tag based on the template file name

    Thread Starter dragonsjaw

    (@dragonsjaw)

    Well the above code was/is easier to spot and read ..
    You are right in that the info is there, this is how one looks on one of my pages:

    ‘page page-id-1105 page-template page-template-page-templatesfull-width-php logged-in custom-background full-width custom-font-enabled single-author’

    So in this instance I guess I am using the full-width template — but I have to dig to see it.

    Where as the other code simply dropped this in:

    <!– TEMPLATE USED –>
    onecolumn-page-no-title.php

    I guess as long as it’s there ….

    thanks

    your code seems to be working in a Twenty Twelve child theme;

    I used this in header.php to output the template file name:

    <!-- TEMPLATE USED: <?php get_current_template( true ); ?> -->

    (unfortunately, it does not give any information of the templates (sub) folder nor if the template is from the parent theme or the child theme)

    Thread Starter dragonsjaw

    (@dragonsjaw)

    Thanks for checking that alchymyth,
    as soon as I have time I will try yours as it is much neater.

    yours as it is much neater.

    this is no different code –

    it is just what I used to output the template file name (in header.php), and using all your code in functions.php of the child theme.

    what code were you using in Twenty Ten to output the template file name?

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Show which template is being used’ is closed to new replies.