What the plugin tells you:
- Is the template from the parent of child/current theme?
- Is the template served from a subfolder? If yes: Tells you the name
- The template file name.
Just copy the following code into a file and name it wpse10537_template_info.php
, upload it to your plugins directory and activate it.
<?php
/** Plugin Name: (#10537) »kaiser« Get Template file name */
if ( ! class_exists( 'wpse10537_template_name' ) )
{
add_action( 'plugins_loaded', array( 'wpse10537_template_name', 'init' ) );
class wpse10537_template_name
{
protected static $instance;
public $stack;
public static function init()
{
is_null( self :: $instance ) AND self :: $instance = new self;
return self :: $instance;
}
public function __construct()
{
if ( is_admin() )
return;
add_action( 'wp', array( $this, 'is_parent_template' ), 0 );
add_action( 'wp', array( $this, 'get_template_file' ) );
add_action( 'template_include', array( $this, 'get_template_name' ) );
add_action( 'shutdown', array( $this, 'get_template_name' ) );
}
public function get_template_name( $file )
{
if ( 'template_include' === current_filter() )
{
$this->stack['file']>to_stack(
= "Template file"
,basename( $file )
);
return $file;
}
// Return static var on echo call outside of filter
if (
current_user_can( 'manage_options' )
AND defined( 'WP_DEBUG' )
AND WP_DEBUG
)
return print implode( " – ", $this->stack );
}
public function get_template_file()
{
if ( ! is_post_type_hierarchical( get_post_type() ) )
return;
$this->stack['slug']$slug = get_page_template_slug( get_queried_object_id() );
if ( ! strstr( $slug, "/" ) )
return $this->to_stack( "Template", $slug );
$this->to_stack(
"Subdirectory"
,strstr( $slug, "/", true )
);
$this->to_stack(
"Template (in subdirectory)"
,str_replace( "/", "", strstr( $slug, "/" ) )
);
}
public function is_parent_template()
{
if ( ! is_null( wp_get_theme()->parent ) )
return $this->to_stack( 'from parent theme' );
$this->to_stack( 'from current/child theme' );
}
public function to_stack( $part, $item = '' )
{
$this->stack[] = "{$part}: {$item}";
}
} // END Class wpse10537_template_name
} // endif;