The global variable $template
contains this information. We can put a filter in the the_content
to print this and make it appear only to the administrator:
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;
}
Main page of the site: using index.php
of Child Theme
Seeing a simple post: the Child Theme nay has single.php
, website using the Parent Theme file
Another option is to print this information as an HTML comment on <head>
:
add_action( 'wp_head', 'sopt_print_template_in_head', 999 );
function sopt_print_template_in_head() {
global $template;
echo '
<!--
TEMPLATE = ' . $template . '
-->
';
}
Good to see you here again!
– Sergio
salve salve salve, Sergio :)
– brasofilo
Long live the brasofilo!!!!!!!!!!!!!!!!!!
– Maniero
hey, @big, Gracias!
– brasofilo