WordPress.org

Ready to get started?Download WordPress

Forums

How do you handle custom template files with Child Themes? (34 posts)

  1. markross67
    Member
    Posted 3 years ago #

    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

  2. Caroline Moore
    Member
    Posted 3 years ago #

    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.

  3. markross67
    Member
    Posted 3 years ago #

    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

  4. Caroline Moore
    Member
    Posted 3 years ago #

    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.

  5. markross67
    Member
    Posted 3 years ago #

    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?

  6. markross67
    Member
    Posted 3 years ago #

    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?

  7. markross67
    Member
    Posted 3 years ago #

    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?

  8. Caroline Moore
    Member
    Posted 3 years ago #

    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.

  9. markross67
    Member
    Posted 3 years ago #

    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.

  10. markross67
    Member
    Posted 3 years ago #

    That would also defeat WordPress' automatic Theme update feature.

  11. Bob Thomas
    Member
    Posted 3 years ago #

    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.

  12. markross67
    Member
    Posted 3 years ago #

    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

  13. Caroline Moore
    Member
    Posted 3 years ago #

    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.

  14. Caroline Moore
    Member
    Posted 3 years ago #

    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.

  15. markross67
    Member
    Posted 3 years ago #

    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

  16. markross67
    Member
    Posted 3 years ago #

    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

  17. markross67
    Member
    Posted 3 years ago #

    Sixhours,

    Here is what is/was confusing me:
    http://codex.wordpress.org/Child_Themes#Template_files

    "... this WordPress feature lets you modify the templates of a parent theme without actually editing them, so that your modifications are preserved when the parent theme is updated."

    But, the method doesn't appear to protect your 'theme updates,' if you have older theme files in your Child Theme folder.

    Therefore, it does appear that you are right, in that, I can't have it both ways. Unless there is still something we are missing.

    Thank you for all your help.
    Mark

  18. @mercime
    Volunteer Moderator
    Posted 3 years ago #

    But, the method doesn't appear to protect your 'theme updates,' if you have older theme files in your Child Theme folder.

    When the parent theme is updated, the template files you transferred to your child theme folder won't be updated, except for features which the theme author might have added in parent theme's functions.php etc. It helps a lot to make notes/comments when you make revisions so you know what to look out for when the parent theme is updated.

    Before making a child theme, make sure that the parent theme you've chosen is made by a reliable theme author and that which is regularly updated like twentyten or twentyeleven theme, etc.

    If the theme you're interested in is not updated regularly, you might want to work on said theme instead of creating a child theme and use the Theme Check plugin to make sure your template tags/functions etc. are up-to-date with latest WP version.

  19. markross67
    Member
    Posted 2 years ago #

    Thanks for the info mercine!

    When the parent theme is updated, the template files you transferred to your child theme folder won't be updated

    I am aware of that, mercine, but, isn't it true that, when the parent theme files are updated, that, they will be automatically overwritten by any core theme files that reside in your child theme?

    And, IF that is true, and I do switch to a theme that is regularly updated, such as the ones that you pointed to, then it is "imperative" to back up those respective theme files, prior to doing any theme updates. Otherwise, your 'core' theme customizations will be overwritten.

    If the theme you're interested in is not updated regularly, you might want to work on said theme instead of creating a child theme and use the Theme Check plugin to make sure your template tags/functions etc. are up-to-date with latest WP version.

    I have never heard of the plugin, 'Theme Check." That sounds very useful! I am going to look into that immediately!

    Thank you,
    Mark

  20. @mercime
    Volunteer Moderator
    Posted 2 years ago #

    when the parent theme files are updated, that, they will be automatically overwritten by any core theme files that reside in your child theme?

    Yes, the template files in child theme trumps the parent theme's template files.

    then it is "imperative" to back up those respective theme files, prior to doing any theme updates. Otherwise, your 'core' theme customizations will be overwritten.

    To clarify, when you upgrade the parent theme, only the files in the parent theme are overwritten. Your customizations in template files which are in the child theme won't be overwritten in the process. Therefore, to keep your child theme updated, you have to check the Change Logs of recently updated parent theme and make revisions as needed.

    It is imperative and always good practice to have a backup of child theme files. As for the parent theme files, if you chose one from WordPress theme repo, each theme there has all versions are available in WP's SVN
    e.g. for Twenty Eleven theme http://themes.svn.wordpress.org/twentyeleven/

    To better understand the concept of parent-child themes, check this series http://themeshaper.com/2009/04/17/wordpress-child-theme-basics/

    I have never heard of the plugin, 'Theme Check." That sounds very useful!

    It's one of the tools used by the WP Theme Reviewers Team on any new/updated theme submitted to the WP theme repository before the theme is released in http://wordpress.org/extend/themes/

  21. markross67
    Member
    Posted 2 years ago #

    Thanks mercime!

    To clarify, when you upgrade the parent theme, only the files in the parent theme are overwritten.

    Yes, I am definitely aware of that. Which is why, if you customize parent theme files, you should always have them backed up.

    Your customizations in template files which are in the child theme won't be overwritten in the process.

    Which is great.

    Therefore, to keep your child theme updated, you have to check the Change Logs of recently updated parent theme and make revisions as needed.

    However, one way or the other, you will either have to change the child theme, in respective to the theme change logs, or, once your theme is automatically updated, use your backed up theme files, and add thee code back into the updated theme files.

    Assuming this is correct, there is really no way to get automatic theme updates, and avoid having to update your theme files, whether it is the parent or child theme. And, if that is the case, I think I would be more inclined to just automatically update my theme, then re-add the customizations into the parent theme files, once they are updated.

    Unless, of course, with Child Themes, there is some real advantage that I am missing, in regards to this subject.

    mercime, going forward, I think I will definitely lean toward WordPress' recommended themes. I really do like twentyeleven. If you are looking for a more business-type look, suffusion is a VERY nice template as well.

    Mark

  22. markross67
    Member
    Posted 2 years ago #

    I apologize:

    From "However..." on, in the above post, I didn't mean to put it in quotes. :)

    Mark

  23. @mercime
    Volunteer Moderator
    Posted 2 years ago #

    You do not make any customization to parent theme files inside the parent theme at all.

    You make any/all customization/s via child theme's style.css, functions.php and template/s files copied over to child theme from parent theme. Note that you don't have to copy all the template files from parent theme into your child theme. You only copy over the template file you want to modify, that which can't be modified either via CSS or by hooking into action/filters etc. via functions.php.

    I think I would be more inclined to just automatically update my theme, then re-add the customizations into the parent theme files, once they are updated.

    Whichever will make your theming much easier :-)

  24. markross67
    Member
    Posted 2 years ago #

    You do not make any customization to parent theme files inside the parent theme at all.

    Yes, when using Child Themes, I am aware of that. :)

    You make any/all customization/s via child theme's style.css, functions.php and template/s files copied over to child theme from parent theme.

    Again, which is super cool. But, in that scenario, if that I do auto update with my theme, the updated files will then be overwritten by the customized theme files in the Child Theme, right? Then, any theme updates in your parent, may also be overwritten.

  25. markross67
    Member
    Posted 2 years ago #

    Mercime,

    Let me ask you this:

    In my case, would 'you' prefer The Child Theme method, or just The Parent?

    Also, when themes are updated, by the respective developer, do they generally give you very specific info in the change logs, so that you can manually update your theme files?

  26. @mercime
    Volunteer Moderator
    Posted 2 years ago #

    Depends on the project and skill set. For some, it's easier to choose a theme and update template as needed - use "Theme Check" plugin and "Log Deprecated Notices" plugin. As for creating child themes, you have to be confident that the parent theme you choose as foundation of your child theme is coded well and will be updated regularly. Not all themes give specific info in change logs, but the good ones do.

  27. markross67
    Member
    Posted 2 years ago #

    Depends on the project and skill set. For some, it's easier to choose a theme and update template as needed - use "Theme Check" plugin and "Log Deprecated Notices" plugin.

    Thanks mercime.

    For me, it seems to make sense to log my own customizations, as I am the one who has personally made them. And, therefore, it would be fairly cut and dry just adding them back in to the updated theme. Keeping in mind, that, you need to update your folder prior to accepting any theme updates, so that your customizations will NOT be overwritten.

    Then, you can just let the Theme updates do their thing.

    Are there a few theme that you would suggest? Besides Twentyten and eleven, are other themes developed specifically by WordPress? I'd like to make sure that I select a them that will have auto updates.

    Thank you,
    Mark

  28. markross67
    Member
    Posted 2 years ago #

    mercime,

    It would be cool to have a plug-in or utility that logged all of 'our' theme customizations against the original theme files. That would be SUPER for adding them back in quickly, after an auto theme update.

    Do you know if such a utility exists?

    Thank you,

    Mark

  29. esmi
    Forum Moderator
    Posted 2 years ago #

    Do you know if such a utility exists?

    Not as far as I am aware and it would be hellish (if not downright impossible) to try and create such a plugin

  30. markross67
    Member
    Posted 2 years ago #

    I'm not so sure about that, esmi.

    The "Theme Check" utility that mercine suggested, apparently uses the same sort of method. It seems to look at an established WordPress set of standards, and compares them to what one has in their Theme files, then outputs the results.

    All you'd need to do is compare file a to file b, and output any thing from b that is not in a. It could could even make an exact copy of file a, and highlight any thing that is in b and not in a, in the outputted file.

Topic Closed

This topic has been closed to new replies.

About this Topic