1

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?

UPDATE:

includes/breadcrumbs.php:

<?php
if ( is_front_page() ) return;

if ( class_exists( 'woocommerce' ) && is_woocommerce() ) {
    woocommerce_breadcrumb();
    return;
}
?>

<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 3

3

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

8
  • My goal is to be able to remove breadcrumbs from pages. One suggestion I found was to remove the code <?php get_template_part('includes/breadcrumbs'); ?> from template files, which is why I posted my original question. Since posting my question, I discovered that I can remove the breadcrumbs by styling the corresponding <div> with display: none;. Is this something you would recommend?
    – Sabuncu
    Mar 14, 2016 at 8:54
  • Hiding something with CSS is sometimes useful and sometimes not. Because this is not sensitive data, you can hide it. Before you do, check if your breadcrumb function in functions.php is wrapped in an if( function_exists() ) statement. If so, please post that complete function inside your question. Mar 14, 2016 at 9:16
  • I checked the functions.php file - there is no reference to breadcrumbs at all. There is an "includes/breadcrumbs.php" file which is included by several template files.
    – Sabuncu
    Mar 14, 2016 at 9:25
  • What code is in that specific file. Mar 14, 2016 at 9:32
  • I put the start of the file into the question. It's a paid theme (Nexus from Elegant Themes).
    – Sabuncu
    Mar 14, 2016 at 9:34
3

You should only copy the files you intend to change, otherwise when the parent theme is updated, it will load the out of date files in the child theme that you didn't edit

Think of it this way, any templates in the child theme override the parent theme. style.css, functions.php etc are not templates, and don't work this way

4
1

You have to copy that file in which you are willing to append and for example if a file resides in themes\abc\xyz\thefile.php so you should have to create same path as in the parent theme. For example child-themes\abc\xyz\thefile.php

hope that answers the question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.