I’m using a Template called D5 Design. They have an update, and I’ve made changes to a few of the PHP files in the Theme files. (changes to text on certain pages mostly) When I do the update, I realize now that I’m going to lose those changes.
My question is – when I create a child-theme, if I want to have those changes from the certain PHP files not get lost, how, where, in what way to put those changes in the child-theme?
Do I copy the folder into the child theme? do I copy just the code from the folder?
I’m completely at a basic mode on this and I just really need someone to explain it. Every post I’ve read so far, makes the assumption that one already knows how the Child-Theme works (even the Codex on Child-Themes.) I’m hoping something can help make this clear to me.
For example I changed a portion of the comments.php file so that the text for comments is no longer generic.
the code looks like this:
$defaults = array('fields' => apply_filters('comment_form_default_fields', $fields),
'title_reply' => __( '(You must register before you can post anything. Please read our Terms Of Service [bottom of the page]. <p> We hold true to them.) <p> <p>State Your Intention for Your Meditation <p> Then Come Back and Share Your Experience' )
);
If I want to have this change be part of the child-theme so it doesn’t get lost, do I:
- Copy the comments.php folder to the child-theme?
- paste the above code into the child -theme?
- paste all of the code in the
comment.php folder in the child-theme? - so far off base, here’s
what you need to do…
There are three core principles to parent/child theme logic in WordPress:
functions.php
files from both parent and child get executed during load, with the child one first (this is a little counter-intuitive so worth remembering).“Template directory” refers to parent theme and “stylesheet directory” refers to child theme. If no child theme is being used they are same and both refer to single current theme.
Each template file is first looked for in child theme, then in parent theme. Note that this natively works for template files only and not theme files in general (such as arbitrary files with PHP code).
So for modification of template files they are typically copied over to child theme and edited there.
Modification of other files is case by case and depends on availability of hooks and how flexible parent theme is about that specific functionality.