To understand how this works, take a look at the source file template-loader.php
. Here you see several lines of statements which determine which template WordPress will load. Near the end is the filter, which allows you to undo all the previous lines.
For instance, one of the lines determines which template to load if is_single
is true. You could use the filter to add extra conditions, for instance to load a different template if is_single
is true and the post is in a certain category. Beware, this still means you would need to have a template file in your child theme (where you also have the filter in fucntions.php
).
Basically, for all templates that WordPress can find through the conventional naming of the template hierarchy, it doesn’t make sense to use the filter. You would only use it if very specific conditions apply under which the template must be called.
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?
- 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]
- Get the current hierarchy php page
- What is singular.php?
- Custom Post Type Plugin: Where Do I Put The Template?
- CPT Template Not Showing – Getting 404
- Archive page showing nothing – issue with WordPress Hierarchy?
- Is it possible to have an index page for taxonomy term for each custom post type it is assigned to?
- LOST in WP Template Hireachy
- How to Handle CSS for Multiple Header header.php Files?
- page_template toggle between 2 templates + 2 permalinks for same post
- Static Front Page problem
- Trying to manage templates on a blog with lots of custom taxonomies
- Taxonomy landing pages
- is_archive() content being shown instead of is_category()
- Categories Template Assistance
- How to apply a custom template for posts by default?
- Which php file lists all the post of a category
- Displaying all Video Post Formats to Page
- How can a Theme Contain no Header File or Footer File?
- Unable to include a template
- Custom post type and taxonomy permalinks – Structure
- WordPress not respecting template hierarchy (fetches index.php instead of single.php or page.php)
- Understanding the WordPress template hierarchy
- Help splitting a custom post type archive into “past” and “upcoming”
- Load parent theme files before child theme functions.php
- Custom Taxonomy term archive template
- When a link doesn’t exist, how to tell WordPress what to do? (404 Error Page)
- Simple way to get two language WP site
- Manipulating show_on_front, page_on_front, page_for_posts and template hierarchy
- Is there a way to set different post templates for parent posts and child posts in the same post type?
- How to Arrange PHP Files to Allow for Multiple Types of Pages?
- WordPress Pagination changes my template
- How to show single category archive
- How to overwrite core/libraries/vendor template with child theme
- Having trouble with Template hierarchy. I Need to create a set of pages that drill down from states to specific locations
- How to use multiple archive templates for a taxonomy?
- WordPress Filtering Custom Post Type by Metadata and Search Heirachy
- How to load parent theme template parts in child theme
- Selected template is not respected for home page in WordPress
- How does WordPress choose archive type template?
- How can I conditionally show different home page templates based on whether or not the user is logged in?
- Will renaming a `content.php` file cause any problems?
- how to force tag page layout to use same as search layout?
- Custom post type not respecting template hierarchy
- get_month_link uses what wordpress template?
- Differentiation between index.php and page.php
- standard custom page template hierarchy for plugins
- Single-page.php template file name not shown
- inserting content of 1 Post to in another with a template hierarchy
- How to display custom post type?
- Where to put custom page templates in theme?
- Custom Post Type homepage template
- Custom term templates
- Getting custom taxonomy posts on archive page
- how to access the $query variable inside taxonomy-xxx.php template file?
- loading custom registration template
- Custom post types templates
- anchor tag in header not working on other pages except the home page
- How to Override Page Template if URL matches query?
- Overriding the template files using a plugin for all themes
- Custom Archive Template for Multiple Categories
- Static page won’t identify template
- custom post template not getting picked for posts with Unicode title
- My WordPress installation doesn’t load correct template
- How do I control what template is shown based upon Taxonomy Term?
- bbPress: modifying template for forum index
- WordPress Custom Post Type – Post Attribute: Template. Template shows up and saves on the back end, but the default theme file is being rendered
- Custom TaxonomyTemplate
- Single taxonomy for different custom post types
- Letting wordpress decide what template and page to use based on condition
- Which template(s) to override to use a different sidebar for blog, single posts, categories, blog archive?
- Different template for subcategories
- Custom Post Type Archive – archive.php is present, but it is not being used
- Templates files for custom post type with custom tags
- Ajax specific template not loading in replacement of index.php
- Show a custom template, no matter the page being viewed, if the user is not logged in
- Most efficient way to have 1 template for parent, 1 template for child categories?
- Passing query variables to a custom page template
- WP Template Hierarchy – Need help choosing the correct templates
- Custom post type category page not working
- List a custom taxonomy’s terms, with links, on the taxonomy page
- 404 on child page template
- Custom taxonomy meta fields
- What is the point of using archive.php instead of index.php?
- Unload templates; disable parent Template Parts using only “theme.json”