Sunday, April 8, 2012

What is the WordPress Page Template name displaying?



A nice solution for debugging (custom) Page Template issues in WordPress. When something is wrong, or you're just not sure which Page Template is rendering for the content page. I have found this hack invaluable in my WordPress work, source is here, thanks for the help. This has saved me countless hours while developing and modifying WordPress themes.

Just place the following code in your functions.php

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'];
}
And put 
get_current_template();
where ever in your theme files that will display in a comfortable place (usually in footer.php (be careful if you have several custom footers), to display the name of the file.



No comments: