Find out what WordPress template file your in

Use this simple function to help you determine what WordPress Template you're currently viewing | Which WordPress Template am I on? Find out here.

Lately I’ve been using this very small little code snippet that’s helped out a ton! It outputs which template your currently using on the particular page your on using the global $template.

What WordPress template file

Update: WordPress template in admin bar

I just modified it again to output the current template into the admin_bar if it’s showing and I’d like to share it with you.

This is all you need to view which template file from your theme you’re using. You should now know if your using home.php, index.php or some random file.

Default image
Austin
πŸ’πŸ½β€β™‚οΈ Husband to Jeana. ⚾️ Dodgers obsessed. πŸ† World Series Champs. πŸ’» Lead Software Engineer @ Beachbody. πŸŒπŸΌβ€β™‚οΈScratch golfer. 🌱 Hydroponic Gardner. 🍿 Plex nerd. πŸš™ '15 WRX & '66 Corvette C2. 🐢 Missing my love Keiki; RIP 😒. Follow me on Twitter @TheFrosty & Instagram @TheFrosty.
Articles: 285

10 Comments

  1. There is a bug in your code.

    if ( !is_user_logged_in() && $current_user->ID != '1' )

    Should say

    if ( !is_user_logged_in() || $current_user->ID != '1' )

    The logic is – if they are not logged in **OR** they do not have your user id, then return.

    Also, I find using the “What the File” plugin works better than this.

    • You are correct Valerio.

      I noticed this a long time ago and updated my local file but forgot to update the post. The code above has been updated.

Leave a Reply

%d bloggers like this: