What theme are you using?
Sometimes you need to not only copy the file to the child theme, but you need to copy the path of the file as well.
So if the parent theme has like /theme/parent-theme/inc/template.php, then you would need to copy the file like this /theme/parent-child/inc/template.php
Thread Starter
wyclef
(@wyclef)
I’m using Uncode. I actually tried to copy the file with the directory structure first. I wonder if I just need to copy the file into the root of the child theme instead?
Seems as tho it should be included in the docs,
https://support.undsgn.com/hc/en-us/articles/213454729-Child-Theme
Yes, move it to the child theme folder.
Thread Starter
wyclef
(@wyclef)
Hmmm, thanks so much for taking a look. That doesn’t seem to work either. I see in the parent theme there is a call in the functions file to the file I want to edit. Do you think I need to include this in the child theme function.php?
if ($ok_php) {
require_once get_template_directory() . '/partials/menus.php';
}
-
This reply was modified 2 years, 10 months ago by
wyclef.
get_template_directory() needs to be changed to get_stylesheet_directory() to work with a child theme. That code is in functions.php and not a template file? That’s unusual. You cannot override theme PHP functions from a child theme unless they have been setup to be “pluggable”. To alter behavior, you would need to go back to the originating template call, copy that template over, then have it call your function instead.
You can also copy over menus.php to your theme’s /partials/ directory and edit that as need be.
Thread Starter
wyclef
(@wyclef)
Ok, we are making progress folks! So if I change the parent theme function to get_stylesheet_directory() and move partials/menus.php to the Child Theme directory and my edits to the PHP in the child theme work. Is this the most practical way to proceed with this and just note the edits made to the parent theme or should I take this a step further and try to get it so no changes need to be made to the parent themes function file and if so how?
No changes at all should ever be made to the parent theme. That is the entire point of a child theme.
Did you follow the instrucitons here?
https://support.undsgn.com/hc/en-us/articles/213454729-Child-Theme
If that doesn’t work properly, you can try this:
https://ww.wp.xz.cn/plugins/generate-child-theme/
The instructions to override your menu in the parent are specifically here,
https://support.undsgn.com/hc/en-us/articles/4409014075665-Override-menus-php-via-Child-Theme-
Thread Starter
wyclef
(@wyclef)
Thank you! That last link cleared this up and things now work. I had checked their support articles but I guess missed that one unfortunately.