The global variable $template
contains this information. We can put a filter on the_content
to print this and make it appear only to the admin:
add_filter( 'the_content', 'sopt_print_template', 20 );
function sopt_print_template( $content ) {
# O valor da global $template vai ser tipo:
# /public_html/wp-content/themes/theme-name/template-name.php
global $template;
# Não executar o filtro se estivermos no backend
# ou se o usuário não for um administrador
if( is_admin() || !current_user_can( 'delete_plugins' ) )
return $content;
# Buscar o nome da pasta e do arquivo
$split_path = explode( '/', $template );
$total = count( $split_path ) - 1;
$theme_and_template = $split_path[$total-1] . '/' . $split_path[$total];
$print = '<strong style="font-size:1em;background-color:#FFFDBC;padding:8px">Current = ' . $theme_and_template . '</strong>';
# Adicionar a informação antes do conteúdo
$content = $print . $content;
return $content;
}
Site home page: using child theme%
Viewingasimplepost:childthemedoesnothasindex.php
,siteusingparenttheme
Another option is to print this information as an HTML comment on single.php
:
add_action( 'wp_head', 'sopt_print_template_in_head', 999 );
function sopt_print_template_in_head() {
global $template;
echo '
<!--
TEMPLATE = ' . $template . '
-->
';
}