WordPress.org

Support

Support » Themes and Templates » How do you handle custom template files with Child Themes?

How do you handle custom template files with Child Themes?

  • Hi,

    I have been hosting a WordPress blog site for almost 3 years; but, at the time, I didn’t know about Child Themes. And, during those 3 years, I have customized several of my theme files.

    I recently decided to start over with a new WordPress install, import my posts etc., and do it properly this time.

    So far, I have found a sufficient amount of info to create my Child Theme, but, I still can not find any good info on how to handle the Theme file customizations (i.e. single.php, comments.php etc.)

    Could anyone help me with this?

    Thank you,
    Mark

Viewing 15 replies - 1 through 15 (of 33 total)
  • Copy the parent theme’s file and put it in the child theme folder.

    Customize the files in the child theme folder however you like–these files will be called first, followed by those from the parent theme.

    So in your example, the single.php file from the child theme will override the single.php file from the parent theme.

    Cool!
    Thanks sixhours! I had a feeling that, that was the approach; but, until now, I have not been able to get affirmation on that.

    If you decide to use a brand new template, you would then need to modify those template files, respectively, of course. Isn’t that right?

    Also,
    I was looking over this link:
    http://codex.wordpress.org/Child_Themes

    Would you say that it accurately describes how to get started? And, is the import statement necessary?

    Thank you,
    Mark

    Correct! You’d need a new child theme for a new parent theme.

    And yes, that guide will get you up and running. The import statement tells the child theme to include all styles from the parent theme–otherwise you’d have to recreate them in the child theme’s style.css.

    And yes, that guide will get you up and running.

    Great!

    I would like to possibly switch themes, but, it would be a lot of work, back-tracking to find all the customizations.

    But, even if I start with the most recent update of my current template, it likely would not be advisable to use the out-dated theme files, anyhow, would it?

    But, even if I start with the most recent update of my current template, it likely would not be advisable to use the out-dated theme files, anyhow, would it?

    I may actually be wrong in that assumption:

    If I am using the exact same template as before – but, the customized theme files in the Child Theme directory, are a little outdated, as long as I have the latest version of my (parent)theme is installed, wouldn’t the most updated ‘core theme updates’ be updated, on my blog site?

    I may actually be wrong in that assumption:

    Or, it sounds like the template files (single.php, comments.php etc.) in the Child Theme, could be from any past template – as the parent theme, whichever theme you chose, is only concerned with the ‘customizations’ within those respective files in the Child Theme. Is that correct, sixhours?

    No. As I understand it, it won’t use just the customizations; it will use the whole file. So if the file in the child theme is outdated, it will use the outdated file with your customizations instead of the updated file from the parent theme.

    So it would be best to customize the most recent version of the theme’s files and keep track of any major theme revisions.

    No. As I understand it, it won’t use just the customizations; it will use the whole file. So if the file in the child theme is outdated, it will use the outdated file with your customizations instead of the updated file from the parent theme.

    But, the whole concept of having a Child Theme is so that I can update my parent theme, automatically, anytime an update is available, ‘without over-riding’ any theme customizations. Which is why my first assumption makes sense:

    If the Child theme files were constantly over-riding the Parent Theme files, you would constantly have any Theme updates over-ridden as well. No?

    That would defeat the entire purpose of having a separate Child Theme. At least for me, it would.

    That would also defeat WordPress’ automatic Theme update feature.

    Hi Mark and Six Hours,
    I’ve been working on creating a child of twentyeleven using the import style.css command as described in the codex material. Finally succeeded in getting it loaded and activated. I am a little confused (probably a lot) but my understanding was that the child theme would reflect all of the content of the parent (because of the import command) except for the new style.css which would be different according to my changes. Is that correct? When I go to the editor in the child theme there is no code for the rest of the blog and only the style.css file which does not open. Do I actually have to do an import all of the files related to the parent or copy and paste to get them into the child?
    Thanks for any help you can offer.

    Hi Bob,
    I’m sorry, but, I am also new to Child Themes, which is why I started this post. 🙂 Therefore, I would be reluctant to get any advise at this point.

    Sixhours may be able to help you; or, you may want to re-post the above question in a new post.

    It’s up to you.

    Thank you,
    Mark

    There’s no way for WordPress to cherry-pick code from within a PHP file–taking only the modified pieces from your child theme and the updated pieces from the parent theme. Not possible, as far as I know.

    It does the next best thing, which is to look for specific theme files (ie. single.php) within the child theme folder first, then if it doesn’t find one it defaults to the parent theme.

    It can’t look within single.php and see that you’ve made modifications to one section, apply only changes from that section, then take the rest from the parent theme’s file.

    If your customizations are so extensive that you’re having to modify almost every parent theme’s file, or if the parent theme changes all its files on a regular basis, it’s probably not worth it to create a child theme.

    Hi Bob,

    Do I actually have to do an import all of the files related to the parent or copy and paste to get them into the child?

    Not all files. You only need to copy over those parent theme files you intend to modify. Copy them into the child theme’s folder, upload and you should see them appear in the Editor.

    Not sure why you can’t open style.css in your child theme, though… that sounds like a different issue.

    There’s no way for WordPress to cherry-pick code from within a PHP file–taking only the modified pieces from your child theme and the updated pieces from the parent theme. Not possible, as far as I know.

    Sixhours,
    I’m going to do a little more reading before I post again. I definitively don’t want to do a lot of work, or waste your time, if I am not going to get the result I am hoping for.

    Of course, what you are saying, above, makes ‘complete sense.’ But, I still believe that I read, that, The Child Theme files are shielded from all automatic theme updates. Therefore, I am going to look a little more into it. I’ll post back in a bit.

    Thank you,
    Mark

    I’m sorry, of course The Child Theme would be shielded. I meant to say, I thought there was a way to somehow achieve what I was hoping for. I’ll go read a bit more.

    Mark

Viewing 15 replies - 1 through 15 (of 33 total)
  • The topic ‘How do you handle custom template files with Child Themes?’ is closed to new replies.
Skip to toolbar