Wednesday, July 17, 2013

Find which template is currently used - Wordpress

Place this bit of code in functions.php. So that any files inside theme can access this.

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'];
}

To find the file name, simply echo this function in any of theme files.

get_current_template()

No comments:

Post a Comment