wordpress技术文档

如何知道wordpress当前页面使用了哪个模板文件?

日期:2020-03-29 阅读:1053

可以使用插件
https://wordpress.org/plugins/which-template-file/
https://wordpress.org/plugins/reveal-template/

或者在模板里写段代码:
http://stackoverflow.com/questions/9405896/how-do-i-get-the-name-of-the-file-that-is-being-used-to-render-the-current-page

add_action( 'wp_head', 'so_9405896_show_template', 999 );

function so_9405896_show_template() {
    global $template;
    echo  'TEMPLATE = ' . basename($template); 
}

-----------------------------

简单点操作,就是在footer.php里加以下代码即可:

<?php 

global $template;

echo '<p style="background:red;color:#fff;text-align:center">'.basename($template).'</p>'; 
?>

这个代码,也可以放在404.php的最前面。