Skip to main content
4 of 7
added 381 characters in body
kaiser
  • 50.8k
  • 27
  • 150
  • 244

An addition (more sweet code) to other answers here.

Template Name

To just get the current page template name, use the following line.

is_page() AND print get_page_template_slug( get_queried_object_id() );

File Name

When you just want to echo the current template file name got with the following

/** Plugin Name: Get Template file name */
function wpse10537_get_template_name( $file )
{
    static $name;
    if ( isset ( $name ) )
        return $name;

    // Set static var
    $name = basename( $file );

    return $file;
}
add_action( 'template_redirect', 'wpse10537_get_template_name' );

This plugin can run as MU-Plugin.

You can then simply echo wpse10537_get_template_name() at any point (in for example a theme template). This avoids cluttering the global namespace.

kaiser
  • 50.8k
  • 27
  • 150
  • 244