I have created a child theme for a Theme, Every thing works fine, except there are some files being required in functions.php of parent theme which I want to override it from the child theme. They have used get_template_directory_uri();
instead of get_stylesheet_directory_uri();
. So it's not overriding it. Code used in function.php is:
require( get_template_directory() .'/inc/custom-functions.php' );
I can't change the parent theme or unhook from child theme. What is the best solution to use the child one as I can't call both at a time, resulting into fatal error. I have checked some answers on stackoverflow, but they do not answer exactly.
Child theme - Overriding 'require_once' in functions.php
This answer suggest to use stylesheet instead of template, but I cannot change parent theme.
I have created a child theme for a Theme, Every thing works fine, except there are some files being required in functions.php of parent theme which I want to override it from the child theme. They have used get_template_directory_uri();
instead of get_stylesheet_directory_uri();
. So it's not overriding it. Code used in function.php is:
require( get_template_directory() .'/inc/custom-functions.php' );
I can't change the parent theme or unhook from child theme. What is the best solution to use the child one as I can't call both at a time, resulting into fatal error. I have checked some answers on stackoverflow, but they do not answer exactly.
Child theme - Overriding 'require_once' in functions.php
This answer suggest to use stylesheet instead of template, but I cannot change parent theme.
Share Improve this question edited Jan 21, 2020 at 11:55 Tom J Nowell♦ 61.2k7 gold badges79 silver badges150 bronze badges asked Jan 21, 2020 at 11:30 Javed AkhtarJaved Akhtar 133 bronze badges 7 | Show 2 more comments1 Answer
Reset to default 3This is not possible, require
is a PHP language construct, it's not a WordPress function, and can't be filtered or overriden via WordPress APIs
These are your options:
If the functionality you want to remove is implemented via actions and filters then:
- Unhook the things you don't want from that file
- Add new hooks that happen after them that attempt to undo what they did
Otherwise, your only options are to:
- Modify the parent theme
- Fork the parent theme
- Choose a new parent theme
- Raise a support ticket with the authors to get it changed to support actions and filters
require
statement, onlyget_template_part
– Tom J Nowell ♦ Commented Jan 21, 2020 at 11:51developer.wordpress
, just a self hosted site – Tom J Nowell ♦ Commented Jan 21, 2020 at 11:55