preg_replace("/^\//", "", str_replace($p, "", $filename)))); } } } add_filter('template_include', 'WhichTemplate\which_template_template_include', 1000); function which_template_template_include($template) { // Check if your on an admin page. if (is_admin()) { // On admin page so don't display menu link. return; } // Check to see if user is logged in. if (is_user_logged_in()) { // User is logged in so define constant for use later on. define('WHICH_TEMPLATE_USED', ltrim(strrchr($template, '/'), '/')); add_filter('admin_bar_menu', 'WhichTemplate\which_template_admin_bar_menu', 1000); } return $template; } function which_template_admin_bar_menu($template) { // Check if your on an admin page. if (is_admin()) { // On admin page so don't display menu link. return; } // Check if user is logged in. if (is_user_logged_in()) { // User is logged in, so display template info. global $wp_admin_bar; $link = get_option("siteurl")."/wp-admin/theme-editor.php?file=".WHICH_TEMPLATE_USED."&theme=".wp_get_theme()->Template; $wp_admin_bar->add_menu( array( 'id' => "which_template_template_file", 'title' => "Template file : ".WHICH_TEMPLATE_USED."", ) ); if (isset($GLOBALS["which_included_templates"])) { foreach ($GLOBALS["which_included_templates"] as $key => $value) { $link = get_option("siteurl")."/wp-admin/theme-editor.php?file=".$value."&theme=".wp_get_theme()->Template; $template_header = "Template"; if (preg_match("/header/i", $value)) { $template_header = "Header"; } else if (preg_match("/footer/i", $value)) { $template_header = "Footer"; } else if (preg_match("/sidebar/i", $value)) { $template_header = "Sidebar"; } $wp_admin_bar->add_menu( array( 'id' => "which_template_".strtolower(str_replace(" ", "_", $value)), 'title' => "$template_header file : ".$key."", 'parent' => 'which_template_template_file' ) ); } } } }