2

Is there any way to see what .php files are being loaded for a particular page?

So say I have a page - www.example.com/page - and on it is loading the header.php, sidebar.php, footer.php, and the page.php, and any other php from plugins. Is there anyway to get a list of these for a certain page?

  • Are you referring only to files that are used for templating? Or all PHP files, even those that have no html inside them? – Tom J Nowell Dec 16 '14 at 17:44
  • Might wanna try an older question of mine: (Is there a hook or function I can use to display all theme files being used on a current page?): wordpress.stackexchange.com/questions/168146/… – RachieVee Dec 16 '14 at 18:57
  • @RachieVee this is probably a stupid question, but can I put all the code from the first example in functions.php? Obviously with the required php tags. – CalvT Dec 16 '14 at 19:07
  • @CalvT Sure can. It's neater G.M.'s way but I also dropped it all in functions.php because I needed to see what it can do first. Just make sure that printing function goes in your footer file. Good luck! – RachieVee Dec 16 '14 at 19:19
  • @RachieVee It works great - but only shows the included theme files? Not the plugin ones? Did you find this? – CalvT Dec 16 '14 at 19:31
3

The following will show the current template file to logged in admins only. If you add to the top of your functions file, you should see this info as the first line.

add_action('wp_head', 'show_template');

function show_template() {
  global $template;
  global $current_user;
  get_currentuserinfo();
  if ($current_user->user_level == 10 ) print_r($template);
}

You will still need to follow the logic of the page template to determine which header, sidebar and footer are loaded, however.

  • this might only show page.php or header.php, but not footer.php, sidebar.php, or other templates that may be loaded – Tom J Nowell Dec 16 '14 at 17:43
  • Not if you call get_template_part – Tom J Nowell Dec 16 '14 at 23:00
2

get_currentuserinfo is deprecated since 4.5.0! Use wp_get_current_user() instead.

add_action('wp_head', 'show_template');

function show_template() {
  global $template;
  global $current_user;
  wp_get_current_user();
  if ($current_user->user_level == 10 ) print_r($template);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.