1

I don't see any way of testing which template file is being loaded, if the template file is not a page template. Otherwise I would use is_page_template().

For instance, I am using a home.php template file to pull in the content from multiple pages(don't ask), how would I check that home.php is the template file being used when viewing the sites root url?

4 Answers 4

2

Just type in some text like "Debug" into the non-Php area of home.php (the part not surrouded by ) and see if it appears. If so, you know that home.php is being used.

2

I do not think this is common practice or that WP tracks such either. Conditional Tags are very flexible and usually sufficient to build conditional logic.

If you really need this I'd look into __FILE__ constant and debug_backtrace().

0

We can see the template file name in body tag by doing a view page source like page-templatesfront-page-php in WordPress twenty twelve theme. If we need to check in code, then get page template slug.

0

If i understand this correctly - I usually echo this somewhere in header.php, to see which template is being used.

<?php echo get_current_template(true);?>

1
  • It will show template only if it is a page template... But OP clearly wants to show template name if it is not a page with custom template... Commented Jan 23, 2019 at 11:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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