• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
NameHero® Blog

NameHero® Blog

Web Hosting Tips & Resources From NameHero

  • AI Agents
    • OpenClaw
    • Claude Code
    • n8n
    • Hermes Agent
    • Open WebUI
    • Docker
  • Hosting
    • Web Hosting
    • WordPress Hosting
    • WooCommerce Hosting
    • Enterprise Hosting
    • Email Hosting
    • HeroicGuard
    • GPU Hosting
    • Website Builder
  • VPS
    • Managed VPS
    • Unmanaged VPS
    • Flex VPS
  • Reseller
  • Gaming
  • Domains
  • Account
  • Blog Home
  • Categories
  • Authors

How To Know Which Template Is Used In WordPress

Bhagwad Park

Published on: October 8, 2018

Categories: WordPress 0

You’ve just installed a new theme. And you love it! However, there is one piece of text you don’t like. Or perhaps a graphic in a certain portion turns you off. “No problem.” you say to yourself. “This is WordPress – I can just modify the correct theme files”.

Except that it’s not easy to find out which file is generating what. Those days are gone.

Modern WordPress pages are “stitched” together from a large number of components. There are a lot of outdated tutorials on the Internet still giving advice to modify a particular WordPress theme file if you want to make changes. These can still work with certain themes, or ones that are out of date. But for the past several years, WordPress has become a lot more dynamic and compartmentalized.

In this tutorial, I’m going to show you which template is used in WordPress. Not just one template however. I’m going to show you how to get all the relevant files that go into making an individual WordPress page.

The Problem: Looking at “single.php” Isn’t Enough

Let’s say that the part of the theme you want to change is displayed when viewing an individual post. Experienced WordPress admins will know that the “single.php” file is responsible for displaying it.

If you don’t know the basic template for the page that you’re viewing, here’s some simple code that will show you the underlying template:

function display_template() {
    global $template;
    echo "Template File Name " . $template;
}
add_action( 'wp_footer', 'display_template');

This will generate output like this at the bottom of every page:

Get the Basic Template

You can see in the screenshot above, that it’s “single.php” which is stored in the global “$template” variable. Great! So you navigate to your WordPress dashboard, click “Appearance->Editor”, and go to your theme’s “single.php” file.

Unfortunately, this is what you see:

WordPress Template Parts

There’s hardly any code inside the box! What happened to the main code of the WordPress loop? What happened to the code showing the meta information? Where is everything??

The answer is simple: single.php is not the only WordPress theme file that is displaying content. WordPress pages now call a bunch of other PHP files and “stitch” together content. What we want is a way to force WordPress to display all the theme files that are being used.

And here’s how to do just that.

The Solution: Getting a Complete List of WordPress Template Files

Instead of the above code showing just a basic template file, use the following code instead. If you don’t know how to pate custom code snippets into WordPress like this, here’s a step by step tutorial on how to do just that.

function display_template() {

$included_files = get_included_files();
$stylesheet_dir = str_replace( '\\', '/', get_stylesheet_directory() );
$template_dir   = str_replace( '\\', '/', get_template_directory() );

foreach ( $included_files as $key => $path ) {
    $path   = str_replace( '\\', '/', $path );

    if ( false === strpos( $path, $stylesheet_dir ) && false === strpos( $path, $template_dir ) )
        unset( $included_files[$key] );
}
echo "Complete list of included files: \n";
echo str_replace(array('&lt;?php&nbsp;','?&gt;'), '', highlight_string( '<?php ' .     var_export($included_files, true) . ' ?>', true ) );
    
}
add_action( 'wp_footer', 'display_template');

Now when you load a page, you get the following output:

Know Which Template is Used

As you can see, this is very different from the previous screenshot. I bet you had no idea that so many files were being used to generate just a simple WordPress post! Note that not only is “single.php” being used, another file called “content-single.php” is also contributing to the page.

This list won’t tell you which of the template files are generating a specific output, but it’s a great starting point. You can narrow down the list based on an educated guess, and finally be able to pinpoint what you need to change.

So far, this is the most comprehensive way I’ve found to display the list of files that go into a single WordPress post. Using it, you can now modify your theme in the right place to get the look you need!

Bhagwad Park Profile Picture
Bhagwad Park

I’m a NameHero team member, and an expert on WordPress and web hosting. I’ve been in this industry since 2008. I’ve also developed apps on Android and have written extensive tutorials on managing Linux servers. You can contact me on my website WP-Tweaks.com!

Related Posts

How To Back Up Your WordPress Site (And Why You Should Do It Today)

In this post, we’ll take a closer look at why backups matter. We’ll also show you different ways to back up your WordPress website.

How to Eliminate Render-Blocking Resources in WordPress (& Why You Should)

Many things can slow down your site, including render-blocking resources. These are CSS and JavaScript files that delay the loading of content on your site. As a result, visitors will have to wait longer to interact with your page, which could lead to frustration and instant exits.  So, what can you do to eliminate render-blocking […]

Blogger vs. WordPress: Which One to Use?

Let's compare WordPress and Blogger across five key areas. Then, we'll show you how to set up a professional blog with WordPress.

What Is Self-Hosted WordPress?

In this post, we’ll differentiate self-hosted WordPress from WordPress.com, and discuss the benefits of the former.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Follow & Subscribe

Exclusive promos, content and more!


Most Popular Posts

NameHero’s Recommended WordPress Plugin and Theme Setup

WordPress Hosting vs. Web Hosting – What’s The Difference?

How To Increase The InnoDB Buffer Pool Size

How To Fix A Stuck All-in-One WP Migration Import

How To Add A Subdomain In Cloudflare

Top Categories

  • WordPress
  • WordPress Tutorials
  • OpenClaw Hosting
  • Enterprise Hosting
  • WooCommerce
  • Web Hosting
  • Resellers
  • Website Security
  • Website Development
  • Website Performance
  • VPS Hosting
  • SEO Tips
  • Announcements
  • Domain Registration
NameHero

NameHero® proudly provides web hosting to over 40,000 customers with 99.9% uptime to over 750,000 websites.

  • Master Card
  • Visa
  • American Express
  • Discover
  • Paypal
Products
  • Web Hosting
  • Managed VPS Hosting
  • Unmanaged VPS Hosting
  • Flex VPS Hosting
  • WordPress Hosting
  • WooCommerce Hosting
  • Reseller Hosting
  • Enterprise Hosting
  • GPU Hosting
  • Email Hosting
  • HeroicGuard
  • Domains
  • Website Builder
  • AI Agent Hosting
Help & Support
  • NameHero Blog
  • NameHero Gaming Blog
  • Support
  • Help Center
  • Migrations
  • Affiliates
  • Gaming Affiliates
  • Call 1-855-984-6263
Company
  • About Us
  • Contact Sales
  • Reviews
  • Uptime
  • We're Hiring

Copyright © 2026 Name Hero, LLC. All rights reserved.
NameHero® is a registered trademark.

  • Privacy Policy
  • Terms of Use
  • Acceptable Use Policy
  • Payment Policy
  • DMCA