Experience the powerful AI writing right inside WordPress
Show stunning before-and-after transformations with image sliders.
Improve user engagement by showing estimated reading time.
Written by Mahmuda Akter Isha
Showcase Designs Using Before After Slider.
To override a WordPress template safely, use a child theme and copy the required template with the same filename and folder structure. Classic themes use PHP files, while block themes use HTML templates or the Site Editor. Always test changes before updating your live website.
WordPress templates control how pages, posts, archives, products, categories, search results, and other sections of a website appear. Although a theme provides default templates, those files may not always support the design or functionality your website requires.
A WordPress template override lets you replace or extend a theme’s default template without editing WordPress core files. Depending on your theme and project, you can override templates through a child theme, create a custom page template, use the WordPress template hierarchy, edit a block template through the Site Editor, or load a template programmatically.
However, each method works differently. Using the wrong filename, folder, directory function, or template type can prevent WordPress from loading your customization.
This guide explains how to override WordPress templates safely in classic themes, child themes, block themes, custom post types, and WooCommerce websites.
A WordPress template override is the process of replacing a default template with a customized version.
For example, a parent theme may use single.php to display every blog post. You could add a customized single.php file to a child theme to change the layout without editing the parent theme.
single.php
You can also create more specific templates, such as:
single-book.php archive-book.php page-about.php category-news.php taxonomy-genre.php
WordPress uses its template hierarchy to determine which file should render each request. It starts with the most specific applicable template and falls back to a more general template when the specific file does not exist.
Template overriding is useful when you need to:
A template hierarchy file, custom page template, and programmatic override are not the same thing.
Understanding this difference can prevent many common WordPress template problems.
page-about.php
template-full-width.php
template_include
/templates/page.html
A file named page-about.php is automatically associated with a page whose slug is about. It does not need to be selected manually.
about
An editor-selectable custom page template normally uses a descriptive filename, such as template-full-width.php, and contains a Template Name header.
Template Name
For pages, WordPress checks an assigned custom template before checking page-{slug}.php, page-{id}.php, page.php, singular.php, and finally index.php.
page-{slug}.php
page-{id}.php
page.php
singular.php
index.php
When someone visits a URL, WordPress identifies the type of content being requested. It then checks the active theme for matching templates in a defined order.
If the most specific template is unavailable, WordPress moves to the next template in the hierarchy. In classic themes, these files normally use the .php extension. Block themes use .html templates, but the general hierarchy remains similar.
.php
.html
For a standard WordPress page, the simplified hierarchy is:
Assigned custom template page-{slug}.php page-{id}.php page.php singular.php index.php
For a page with the slug about, WordPress may look for:
page-about.php page-42.php page.php singular.php index.php
For an individual post or custom post type entry, WordPress may use:
single-{post-type}-{slug}.php single-{post-type}.php single.php singular.php index.php
For a custom post type named book, you could create:
book
single-book.php
For an archive, WordPress may check:
archive-{post-type}.php archive.php index.php
For a book custom post type archive, the file would be:
archive-book.php
category-{slug}.php category-{id}.php category.php archive.php index.php
For a category with the slug news, use:
news
category-news.php
tag-{slug}.php tag-{id}.php tag.php archive.php index.php
taxonomy-{taxonomy}-{term}.php taxonomy-{taxonomy}.php taxonomy.php archive.php index.php
For a custom taxonomy named genre, use:
genre
taxonomy-genre.php
For the fiction term inside that taxonomy, use:
fiction
taxonomy-genre-fiction.php
author-{nicename}.php author-{id}.php author.php archive.php index.php
front-page.php home.php search.php 404.php date.php attachment.php comments.php
You do not need to create every possible template. Create only the files required for your design, and WordPress will continue using fallback templates for everything else.
Before modifying a template, determine which type of WordPress theme is active.
A classic theme usually:
get_header()
get_footer()
A block theme usually:
/templates/index.html
theme.json
The presence of /templates/index.html is a key distinction that makes a theme a block theme.
Some themes combine classic PHP templates with selected block-theme features. These are often described as hybrid themes. Inspect the active theme’s files before choosing an override method.
Directly editing a third-party parent theme is risky. When the theme is updated, its files may be replaced and your modifications can be lost.
A child theme inherits the parent theme’s functionality while allowing you to add or override templates separately.
WordPress allows a child theme to override a parent theme’s template, template part, or pattern by supplying a matching file. However, a child theme’s functions.php does not replace the parent theme’s functions.php; both files are loaded.
functions.php
wp-content/ └── themes/ ├── parent-theme/ └── parent-theme-child/ ├── style.css └── functions.php
Add the following header to the child theme’s style.css file:
style.css
/* Theme Name: Parent Theme Child Description: Custom child theme for safe template overrides Template: parent-theme Version: 1.0.0 */
The value of Template must exactly match the parent theme’s folder name.
Template
Activate the child theme from Appearance → Themes before adding your overrides.
Depending on how the parent theme loads its stylesheets, you may also need to enqueue the parent stylesheet in the child theme’s functions.php. Check the parent theme’s documentation because not every theme handles styles in the same way.
The most common way to override a classic WordPress template is to copy it into the child theme.
Suppose the parent theme contains:
wp-content/themes/parent-theme/single.php
Copy that file to:
wp-content/themes/parent-theme-child/single.php
Edit only the child theme copy.
When WordPress needs single.php, it will use the child theme version instead of the matching parent theme version.
If the parent theme uses:
parent-theme/template-parts/content/content-page.php
Place the override at:
parent-theme-child/template-parts/content/content-page.php
The filename and relative directory structure should match.
WordPress functions such as get_template_part() are designed to allow reusable template sections to be overloaded by child themes.
get_template_part()
A general child theme template does not always override a more specific parent theme template.
For example:
Child theme: category.php Parent theme: category-news.php
When WordPress displays the news category, the more specific category-news.php in the parent theme may be selected before the general category.php in the child theme.
category.php
To override that category, create this file in the child theme:
WordPress considers template specificity as well as whether the file belongs to the parent or child theme.
To automatically apply a template to one page, name the template using the page slug or ID.
For a page located at:
example.com/about/
Create:
A simple example could look like this:
<?php /** * Template for the About page. */ get_header(); ?> <main id="primary" class="site-main site-main--about"> <?php while ( have_posts() ) : the_post(); ?> <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> <header class="entry-header"> <h1 class="entry-title"><?php the_title(); ?></h1> </header> <div class="entry-content"> <?php the_content(); ?> </div> </article> <?php endwhile; ?> </main> <?php get_footer();
Upload the file to the root of the active child theme:
parent-theme-child/page-about.php
WordPress will automatically load it for the page with the about slug.
You do not need to add a Template Name header or select the template from the editor for this method.
An assignable custom page template is useful when the same layout should be available for multiple pages.
Create a file such as:
Add a template header:
<?php /** * Template Name: Full Width Page * Template Post Type: page */ get_header(); ?> <main id="primary" class="site-main site-main--full-width"> <?php while ( have_posts() ) : the_post(); ?> <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> <header class="entry-header"> <h1 class="entry-title"><?php the_title(); ?></h1> </header> <div class="entry-content"> <?php the_content(); ?> </div> </article> <?php endwhile; ?> </main> <?php get_footer();
Upload it to the child theme. You can then edit a page and select Full Width Page from the Template setting.
WordPress page templates can also support posts and custom post types when those types are included in the Template Post Type header.
Template Post Type
<?php /** * Template Name: Content Without Sidebar * Template Post Type: page, post, book */
Only include post types for which the template has been properly designed and tested.
The standard single.php file controls individual posts when no more specific template is available.
To customize all standard blog posts, add:
To customize a custom post type called book, add:
Example:
<?php /** * Single Book template. */ get_header(); ?> <main id="primary" class="site-main"> <?php while ( have_posts() ) : the_post(); ?> <article id="post-<?php the_ID(); ?>" <?php post_class( 'single-book' ); ?>> <header class="book-header"> <h1><?php the_title(); ?></h1> </header> <div class="book-content"> <?php the_content(); ?> </div> </article> <?php endwhile; ?> </main> <?php get_footer();
Make sure the filename uses the registered post type slug, not its singular label.
For example, if a post type is registered as:
register_post_type( 'book', $args );
The correct filename is:
It is not:
single-books.php
When the custom post type has archives enabled, you can create:
<?php /** * Book archive template. */ get_header(); ?> <main id="primary" class="site-main book-archive"> <header class="page-header"> <h1><?php post_type_archive_title(); ?></h1> </header> <?php if ( have_posts() ) : ?> <div class="book-grid"> <?php while ( have_posts() ) : the_post(); ?> <article id="post-<?php the_ID(); ?>" <?php post_class( 'book-card' ); ?>> <h2> <a href="<?php the_permalink(); ?>"> <?php the_title(); ?> </a> </h2> <?php the_excerpt(); ?> </article> <?php endwhile; ?> </div> <?php the_posts_pagination(); ?> <?php else : ?> <p><?php esc_html_e( 'No books were found.', 'your-text-domain' ); ?></p> <?php endif; ?> </main> <?php get_footer();
After changing a custom post type’s rewrite or archive settings, you may need to visit Settings → Permalinks and save the settings once to refresh rewrite rules.
Do not repeatedly flush rewrite rules on every page load because that adds unnecessary work to normal requests.
WordPress lets you create unique archive layouts for categories, tags, and custom taxonomy terms.
category.php category-news.php category-12.php
tag.php tag-tutorials.php tag-18.php
For a taxonomy registered as genre:
For only its fiction term:
A dedicated taxonomy template can be useful when the archive needs custom introductory content, filters, field values, cards, or a layout that differs from standard blog archives.
Large templates are often divided into reusable sections called template parts.
A classic theme may load a part using:
get_template_part( 'template-parts/content', 'single' );
WordPress will look for:
template-parts/content-single.php
To override the part, copy the matching file into the child theme:
parent-theme-child/template-parts/content-single.php
You can also create a fallback:
template-parts/content.php
WordPress first attempts to load the more specific named part before falling back to the general part.
Use template-part overrides when you need to change only one reusable section. Replacing a small part is often easier to maintain than copying an entire page template.
Sometimes a filename alone is not enough. You may need to load a custom template based on page data, a custom field, user capability, or another condition.
The template_include filter runs immediately before WordPress includes its selected template, making it suitable for changing the final template path.
Add this code to the child theme’s functions.php or a site-specific plugin:
<?php /** * Load a custom template for the About page. * * @param string $template Current template path. * @return string */ function codecanel_load_about_template( $template ) { if ( ! is_page( 'about' ) ) { return $template; } $custom_template = locate_template( array( 'templates/about-page.php' ) ); if ( $custom_template ) { return $custom_template; } return $template; } add_filter( 'template_include', 'codecanel_load_about_template', 99 );
Create the corresponding file:
parent-theme-child/templates/about-page.php
The locate_template() function searches the active child theme before searching the parent theme, which makes the override compatible with child-theme workflows.
locate_template()
Do not create a template path directly from unvalidated user input. Template filenames should come from a controlled list of trusted values.
get_template_directory()
This code can cause problems in a child theme:
get_template_directory() . '/templates/about-page.php';
When a child theme is active, get_template_directory() returns the parent theme directory. It does not point to the child theme.
Depending on the task, use one of these instead:
locate_template() get_stylesheet_directory() get_theme_file_path()
locate_template() is usually the best choice when you want WordPress to search the child theme first and then fall back to the parent theme.
Block themes use block markup inside .html template files.
Their top-level templates belong in:
your-theme/templates/
Common block template files include:
templates/index.html templates/page.html templates/single.html templates/archive.html templates/search.html templates/404.html templates/front-page.html
Block theme template parts commonly belong in:
your-theme/parts/
Examples include:
parts/header.html parts/footer.html parts/sidebar.html
WordPress officially defines /templates as the location for distributable block templates.
/templates
Go to:
Appearance → Editor → Design → Templates
Select the template you want to modify, edit its blocks, and save the changes.
When a theme-provided template is edited through the Site Editor, WordPress keeps the original theme file and stores a customized version in the database. That customized version can take priority over the file in the active theme.
This explains a common problem: you may edit templates/page.html, but the front end continues showing an older design saved through the Site Editor.
templates/page.html
To resolve it:
Resetting removes the saved customization and restores the template supplied by the theme.
Suppose the parent block theme contains:
parent-theme/templates/single.html
Create the matching file in the child block theme:
parent-theme-child/templates/single.html
A basic block template could contain:
<!-- wp:template-part {"slug":"header","tagName":"header"} /--> <!-- wp:group {"tagName":"main","layout":{"type":"constrained"}} --> <main class="wp-block-group"> <!-- wp:post-title {"level":1} /--> <!-- wp:post-content {"layout":{"type":"constrained"}} /--> </main> <!-- /wp:group --> <!-- wp:template-part {"slug":"footer","tagName":"footer"} /-->
You can edit block markup directly or build the layout visually in the Site Editor and export the completed theme files.
Block themes can register editor-selectable custom templates through the customTemplates property in theme.json.
customTemplates
Add:
{ "$schema": "https://schemas.wp.org/trunk/theme.json", "version": 3, "customTemplates": [ { "name": "landing-page", "title": "Landing Page", "postTypes": [ "page" ] } ] }
Create the matching template file:
templates/landing-page.html
<!-- wp:template-part {"slug":"header","tagName":"header"} /--> <!-- wp:group {"tagName":"main","layout":{"type":"constrained"}} --> <main class="wp-block-group"> <!-- wp:post-title {"level":1,"textAlign":"center"} /--> <!-- wp:post-content /--> </main> <!-- /wp:group --> <!-- wp:template-part {"slug":"footer","tagName":"footer"} /-->
After registration, users can select Landing Page from the page’s Template setting.
The customTemplates setting is designed for selectable single post, page, and custom post type templates. It is not the method used to register category or archive hierarchy templates.
WooCommerce includes PHP templates for product pages, archives, cart components, emails, account areas, and other store content.
For classic WooCommerce templates, the original files are located under:
wp-content/plugins/woocommerce/templates/
Do not edit those plugin files directly. Plugin updates will replace them.
Instead, copy the required file into a woocommerce directory inside the active child theme.
woocommerce
Copy:
wp-content/plugins/woocommerce/templates/single-product.php
To:
wp-content/themes/your-child-theme/woocommerce/single-product.php
wp-content/plugins/woocommerce/templates/single-product/product-image.php
wp-content/themes/your-child-theme/woocommerce/single-product/product-image.php
Preserve the directory structure below WooCommerce’s /templates folder.
A full template override is not always necessary.
When you only need to move, remove, or insert one element, a WooCommerce action or filter may be easier to maintain than copying an entire template.
Use a full override when the HTML structure requires substantial changes. Use hooks when the existing structure is acceptable and only a targeted adjustment is needed.
WooCommerce occasionally updates its template files. Your copied version does not update automatically, so an old override can become incompatible with the current plugin version.
Review the WooCommerce status report for outdated template notices. When an override is outdated:
WooCommerce recommends updating the copied template and reproducing your required changes when its template structure changes.
A classic theme can declare WooCommerce support using a woocommerce.php file. However, that file can take priority over woocommerce/archive-product.php, preventing the archive override from being used as expected.
woocommerce.php
woocommerce/archive-product.php
Check whether the active theme already contains:
before troubleshooting an ignored archive-product.php file.
archive-product.php
WooCommerce also provides block-based templates and components. A block theme can supply templates such as:
templates/single-product.html
That theme template can take priority over the WooCommerce default Single Product template.
Block-based cart and checkout pages should continue rendering their assigned page content through the Post Content block. Removing the Cart or Checkout block from the page content can break the expected experience.
When an override does not work, first confirm which template WordPress is actually using.
During development, you can temporarily log the selected template:
<?php /** * Log the selected template while WordPress debugging is enabled. * * @param string $template Selected template. * @return string */ function codecanel_log_selected_template( $template ) { if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { error_log( 'WordPress template: ' . wp_basename( $template ) ); } return $template; } add_filter( 'template_include', 'codecanel_log_selected_template', 999 );
Remove the snippet after troubleshooting.
You should also check:
Possible causes:
Solution:
Confirm the active child theme, inspect the hierarchy, and copy the exact relative path from the parent theme.
Use a valid template header:
<?php /** * Template Name: Full Width Page * Template Post Type: page */
Then reload the editor.
This is expected.
page-about.php is an automatic hierarchy template, not necessarily an editor-selectable template.
To create a selectable template, use a different filename and add a Template Name header.
WordPress uses index.php as the final fallback when it cannot find a more specific matching template.
Check:
Make sure the filename uses the registered post type key:
single-{post-type}.php
For:
register_post_type( 'portfolio', $args );
Use:
single-portfolio.php archive-portfolio.php
Do not use the post type’s display label unless it is also the registered key.
The post type may not have archives enabled, or rewrite rules may need to be refreshed.
Verify that registration includes an appropriate archive setting, then visit Settings → Permalinks and save once.
Clear:
For block themes, also check whether a customized template saved in the Site Editor is overriding the file.
get_template_directory() points to the parent theme when a child theme is active.
Use locate_template(), get_stylesheet_directory(), or get_theme_file_path() when the child theme should take priority.
get_stylesheet_directory()
get_theme_file_path()
/woocommerce/
A Site Editor customization may be stored in the database.
Open Appearance → Editor → Templates and reset or clear the customization for the affected template.
A broken PHP template can cause a fatal error or incomplete page output. Test changes on staging before deploying them to a live website.
Back up the database and files before changing themes, templates, plugin overrides, or functions.php.
Core modifications are overwritten during updates and can create security and maintenance problems.
Use a child theme or a site-specific plugin so updates do not remove your work.
Every copied template becomes code you may need to maintain. Do not duplicate an entire parent theme when you only need one file.
When an action, filter, template part, or block pattern can achieve the result, use that smaller customization instead of copying a full template.
Escape dynamic output, sanitize incoming values, use translation functions, and avoid placing sensitive business logic directly inside view templates.
esc_html() esc_attr() esc_url() sanitize_text_field() wp_kses_post()
Templates should mainly control presentation.
Move reusable data processing and complex logic into:
Then pass the prepared information into the template.
Add a short comment explaining:
This is especially important for WooCommerce templates.
After updating a parent theme, WordPress, or WooCommerce, compare major template changes with your child theme copies.
Test templates with:
Use semantic headings, visible focus states, keyboard-friendly controls, form labels, descriptive links, and appropriate landmark elements.
Avoid expensive database queries inside loops. Reuse prepared data, optimize media, and load assets only where they are required.
page-42.php
archive.php
tag.php
tag-tutorials.php
author.php
search.php
404.php
home.php
front-page.php
/templates/single.html
/parts/header.html
/woocommerce/single-product.php
Learning how to override WordPress templates gives you much greater control over your website’s layout and functionality.
For classic themes, the safest approach is generally to create a child theme and add a matching or more specific PHP template. For reusable editor-selectable layouts, create a properly registered custom page template. For conditional behavior, use template_include with a child-theme-aware function such as locate_template().
Block themes use a different workflow. Their templates are built with block markup, stored in the /templates directory, and can also be customized through the Site Editor. Because Site Editor changes may be stored in the database, always check for saved customizations when a file-based block template appears to be ignored.
WooCommerce templates require additional maintenance because copied files can become outdated as the plugin evolves. Override only what you need, use hooks for smaller changes, and review customized templates after updates.
By following the template hierarchy, preserving child theme compatibility, and choosing the smallest effective customization method, you can build flexible WordPress layouts without making future updates unnecessarily difficult.
Technically, yes. You can edit a custom theme you fully control, use a site-specific plugin with template filters, or edit a block template through the Site Editor.However, directly modifying a third-party parent theme is not recommended because theme updates can replace your changes.
For a classic theme, create a child theme and override the appropriate PHP template. For an assignable layout, create a template with a Template Name header. For a block theme, use the Site Editor or add an HTML file to the theme’s /templates directory.
This page was last edited on 23 July 2026, at 6:30 pm
Your email address will not be published. Required fields are marked *
Comment *
Name *
Email *
Website
Save my name, email, and website in this browser for the next time I comment.
How many people work in your company?Less than 1010-5050-250250+
By proceeding, you agree to our Privacy Policy