Find out in this tutorial how to display the name of the template being used on a page in the top WordPress admin bar using code.
If, as in my case, you also handle a lot with themes and use specific template files, surely you’ve missed at some point knowing which template is being loaded on a certain page.
There are plugins, like Query Monitor, that show you this information, but they also do many other things that you don’t always need.
So I looked for a quick and easy way to know at a glance which template file is loading.
This is the final result:
If you too have found yourself in the same situation, I’m sure this tutorial will come in handy. 😉
Snippet to display the template file loaded on a page in the WordPress admin bar
Add the following code at the end of functions.php or in your functionality plugin:
To see this and another 1097 code snippets of this website, login or subscribe here.
In this case, you use the admin_bar_menu
hook in combination with the global variable $template
to display the name of the template file that is loaded on the page in the top WordPress admin bar.
You also use the priority “40”, so that it is displayed right after the site name (My Osom Site, in this example), but you can modify it if you prefer it to appear before or after.
Conclusion
With a few lines of code you can get the name of the template file being loaded displayed in the WordPress admin bar.
Any questions? I read you in the comments.
And if you want to give me any suggestion for future tutorials, leave it in the contact form. Advantages of being a subscriber. 😉