How to Override Parent Template Files in WordPress
Using a child theme to modify the stylesheet of an existing WordPress theme is tremendously powerful. A talented CSS developer can use this technique to create an amazing variety of layouts and designs.
However, this is just the beginning of the power of child themes. Although every child theme overrides the parent theme’s style.css file, the child theme can override the parent theme’s template files, too. However, child themes aren’t limited to just overriding template files; when needed, child themes can also supply their own template files.
Template files are PHP files that WordPress runs to render different views of the site. A site view is the type of content being looked at. Examples of different views are home, category archive, individual post, and page content. Some examples of common template files are index.php, archive.php, single.php, page.php, attachment.php, and search.php.
You might wonder what purpose is served by modifying template files of a parent theme. Although modifying a parent theme’s stylesheet allows for some very powerful control over the design, it can’t add new content, modify the underlying site structure, or change how the theme functions. To get that level of control, you need to modify the template files.
When both the child theme and parent theme supply the same template file, the child theme file is used. The process of replacing the original parent template file is known as overriding. Although overriding each of the theme’s template files can defeat the purpose of using a child theme — because updating those template files won’t enhance the child theme — sometimes you have to override to produce the results you need.
The easiest way to customize a specific template file in a child theme is to copy the template file from the parent theme folder to the child theme folder. After the file is copied, you can customize it, and the changes are reflected in the child theme. A good example of a template file that can be overridden is the footer.php file. Customizing the footer allows for site-specific branding.