WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Show which template is being used (6 posts)

  1. dragonsjaw
    Member
    Posted 1 year ago #

    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'];
    }
  2. esmi
    Forum Moderator
    Posted 1 year ago #

    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

  3. dragonsjaw
    Member
    Posted 1 year ago #

    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

  4. alchymyth
    Forum Moderator
    Posted 1 year ago #

    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)

  5. dragonsjaw
    Member
    Posted 1 year ago #

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

  6. alchymyth
    Forum Moderator
    Posted 1 year ago #

    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?

Topic Closed

This topic has been closed to new replies.

About this Topic