Should template files be copied to the child theme for editing?

I know that the style.css file needs to be copied to the child theme before being edited for changes. Is that also true for template.php files? If so, do I need to just copy the specific template file only, or should I copy all?



if ( is_front_page() ) return;

if ( class_exists( 'woocommerce' ) && is_woocommerce() ) {

<div id="breadcrumbs"<?php if ( function_exists( 'bcn_display') ) echo ' class="bcn_breadcrumbs"'; ?>>
    <?php if(function_exists('bcn_display')) { bcn_display(); }
          else {
            $et_breadcrumbs_content_open = true;
            <span class="et_breadcrumbs_content">
                <a href="<?php echo esc_url( home_url() ); ?>" class="breadcrumbs_home"><?php esc_html_e('Home','Nexus'

3 Answers

Generally, you do not need to copy the complete parent stylesheet to your child theme, you can just copy the particular code in question to your child theme’s stylesheet and modify that.

As for functions.php and any other functions related files, you cannot copy that to your child theme as this will lead to a cannot redeclare fatal error. There are a few write-ups on this, so be sure to use the site search for this.

Templates files should always be modified in a child theme (if you are not the parent theme’s author) as templates are theme territory. You only need to copy the affected templates. It should be noted, for page templates, you need to keep the same file structure as the parent theme.

The real question is if whether or not you should copy a template and modify it. With the large amount of native filters and actions available to filter template tags, template parts, the loop itself, the posts array, nav menus, headers and footer, etc etc, it has became increasingly easy to change something via a custom plugin without having to directly alter template files itself. Changing these specifics via their respective filters and actions via a plugin have the added benefit of making these changes available across any theme used at any given time. It would be beneficial to sit down and decide what you would need to change and whether that change would be needed when you change themes before jumping in and copying a template file to a child theme to modify it.

Some of the big commercial themes have added theme specific filters which you can use to filter certain things within a template. In most cases you can alter a template through just these filters, in which case you would use these filters in your child theme’s functions file to alter the parent template’s output accordingly.

If your changes cannot be done through filters and actions, then yes, the correct way would be to copy that particular template to your child theme and modifying it there. The only drawback will then be that you would need to manually keep those templates updated

Leave a Comment