Assuming that you’re wanting to determine which template page is currently being displayed, within the template hierarchy, the easiest way to do so is via the output of body_class()
.
However, if you need to return this information programmatically, the easiest way might be to call get_body_class()
, and then evaluate the array of classes returned. Given the way that get_body_class()
steps through each query conditional itself (and the template loader does likewise), I’m guessing that core doesn’t have a more abstracted approach.
Related Posts:
- Template Hierarchy: confused with index.php, front-page.php, home.php
- How to use a specific category archive index as the site front page?
- Overriding default template if page slug and post type are same
- Change Page Template Based on Category
- Load custom template for specific GET parameter
- where is the code that executes the template hierarchy?
- WordPress Page Hierarchy
- How to force sub-product-category to use the parent category template
- How to determine the template loaded when you are not an Admin?
- Template hierarchy override
- How to define the template priority between built-in categories and custom taxonomies?
- What is the difference between the “Main Index Template”(index.php) and HomePage(front-page.php)
- About template hierarchy
- Front-Page.php and Index.php
- Displaying a custom post type and an archive page
- Which page is referring to *all posts by author*?
- How to determine top level template file in functions.php? [duplicate]
- How to make child categories recognize parent’s template displays
- Template for specific post of custom post type
- Loading partial templates with AJAX/PJAX
- Different template for subcategories
- Different templates for parent and children categories/taxonomies
- How to use same theme template for multiple taxonomy terms?
- Custom Post Type with Nested Taxonomy and Template Files
- Store Page Template Files in a Subfolder
- Template Hierarchy for get_header()
- Single page template for custom post_type
- WooCommerce Template overriding not working with woocommerce.php
- Load template file without a post type
- WordPress Template Hierarchy
- Any tag pagination page (except the 1st page) loads index.php template instead of tag.php
- Where to put my global functions?
- What should I put on my index.php?
- Rewrite URL for only archive page (custom post type)
- Templating of a specific post ID
- For custom templates, is it better to use `template_include` or `type_template`?
- WordPress Theme Development: How to redirect templates the right way?
- Template Hierarchy tag-{slug}.php directory
- Custom post type not using it’s own single-postname.php
- Display Categories, Sub-categories, and Sub-sub-categories on separate pages
- Inheritance of parent theme plugin files in a child theme
- Category-slug.php not being used
- Custom post type templating problem
- How to make use of WP templates within a nested site structure?
- Single page site with history.js
- Custom post type showing index.php
- redirect automatic page that serves custom posttype content
- How To Pass Current Post Type ID from Single Template To Custom Page Template
- How do I check if the user is on a taxonomy term parent, child or grandchild page?
- WordPress Doesn’t Generate Taxonomy Archive
- CPT Template Not Showing – Getting 404
- Categories overview that links to page displaying posts
- Custom templates vs page-slug
- rewrite taxonomy-{taxonomy}-{term}.php terms
- the_excerpt() in content.php and get_template_part() in single.php
- Override Taxonomy Template
- Use one template only for custom post type archives?
- Custom Empty Results page for my Custom Post Type
- single.php with different look by category
- Use meta boxes inside an archive page template for Woocommerce
- Use different template than author.php for get_author_posts_url()
- Restricting page templates by blog_id in multisite network
- Custom Post Type Template Hierarchy – Single post template
- Can I assign a Folder for Post Formats, without it affecting WordPress’ fallback/hierarchical system?
- What Must to Display the “mysite.com/category” URL?
- Creating page & post templates without template file
- Template hierarchy: how to let category.php conditionally-load archive.php?
- The best way to create pages like an ‘about’, ‘contact’ and etc [closed]
- Assigning custom page templates to a static blog page
- WordPress Page doesn’t load the template selected
- localizing variable on front-page.php template fails but succeeds on single page and taxonomy archive
- Using index.php as page template
- Organize template parts and page templates in folders in regards of template hierarchy
- Archive page of taxonomy returns a 404 error
- Is it possible to set archive.php instead of index.php to display blog?
- Prioritise Pages over Taxonomy Term Root Archive, but not Taxonomy Term Child Archives
- WordPress hierarchy clarification, does post_type_archive take precedence over taxonomy-term archive?
- User role templates
- Media item permalink goes to source file instead of attachment.php
- Templating advice sub posts of a CTP
- which template should I use for single category post?
- Specific template for subcategory of custom taxomy
- Get link for taxonomy to show top-level terms
- URL Rewrite and Archive Template Files – Post Type vs. Taxonomy
- Different taxonomy.php for different custom post types
- How to put articles under a /blog directory?
- Single Post Templates Doubt
- How to add dynamic content to posts page, archive, taxonomies, search, author, etc?
- Use different file includes for single.php
- Page Templates Used in Custom Post Type
- Needed to change slug to access page
- Loading custom page template on a one page website
- How to display custom taxonomy
- CPT Template Not Showing – Getting 404
- WordPress doesn’t respect the template hierarchy?
- How to modify/ customise NextGen Gallery’s templates? [closed]
- How can I sort posts ascending by post title for a specific post type, but on a category archive template?
- Custom Taxonomy Template Variables Available?
- What is the point of using archive.php instead of index.php?
- I’m building a WordPress theme and noticed that the 404 page template runs along with the corresponding templates for each page. Any idea why?