If you ever played with WordPress theme files and tried to modify it by yourself, you probably already heard and learnt about the WordPress template hierarchy.
However, sometimes it’s hard to predict what template file is being used and loaded on the current page by just looking at the WordPress website frontend and the current page url. This can become even trickier if you are wrangling with a custom theme, made by someone else. Or, there might be specific plugins which hijack and override theme default template files. Yikes!
Show what template file is being used in WordPress
Luckily, there is a quick and easy way to find out the template being used. You can just add this little code snippet in your theme functions.php file:
1 2 3 4 5 6 7 8 9 10 | //For example, you can paste this into your theme functions.php file function meks_which_template_is_loaded() { if ( is_super_admin() ) { global $template; print_r( $template ); } } add_action( 'wp_footer', 'meks_which_template_is_loaded' ); |
That’s it! Make sure you are logged in, look at the very bottom of your website and you will see the path to the WordPress template file being loaded on the current page. Below is an example how it looks like on our own Meks website.
Detect which WordPress template file is currently being loaded (plugin solution)
While we personally prefer the above solution, as it is probably easier to just comment/uncomment this piece of code whenever you need it, there are a couple of plugins which may help you to achieve the similar thing.
Fell free to install and experiment with one of these plugins: