首页 > 解决方案 > 捕获用于呈现我的网页的 php 文件的代码

问题描述

我正在尝试确定在我的网站 Wordpress 和 Woocommerce 上的页面上使用了哪些 php 文件。我利用此代码在我可以检查的页面上的 html 注释中捕获关联的 php 文件名。这段代码似乎工作,但也许太好了。在我网站的一个非常基本的页面上,生成的评论列出了 1,827 个不同的 php 文件。它真的要经过那么多文件才能生成一个网页吗?这段代码有问题吗?或者有没有办法将输出文件名缩小到定义页面功能的主要文件名?

<?php echo '<!--'; // you can display this code or show it in an HTML comment
$files = get_included_files();
if ($display_only_theme_files === true) {
  $theme_folder = get_template_directory();
  foreach ($files as $key => $file) {
    if (strstr($file, $theme_folder) === false) {
      unset($files[$key]);
    }
  }
}
print_r($files);
echo '-->'; // you can display this code or show it in an HTML comment
?> 

标签: phpdebuggingwoocommercecustom-wordpress-pages

解决方案


推荐阅读