How to override a parent file in a child Wordpress theme when parent file is being required in functions.php
Hello @QuestionerNo27,
It's been a long time since you asked this but I've also been looking for an answer for 2 days as I was facing the same issue. There is the answer, simple like "Hi":
- You dont need the
inc
folder in your child theme nor thetemplate-tags.php
file. - You just have to copy the function(s) you want to override from your parent
template-tags.php
and paste it into your child themefunctions.php
In my case, I wanted to overridefunction mytheme_posted_on()
from my parenttemplate-tags.php
And it's now working. Thanks to https://wordpress.org/support/topic/inc-folder-in-child-theme (Stephencottontail answer)
I had a similar problem where I wanted to make changes to the layout of the header in my child theme within the template-tags.php.
The solution that worked for me was to use the following line in my functions.php file in my child theme:require get_stylesheet_directory() . '/inc/template-tags.php';
I was using the original line from the the Parent them in functions.php: require get_template_directory() . '/inc/template-tags.php';
Using the function get_template_directory() was not working because this function will always return the parent theme directory.
Using the function get_stylesheet_directory() worked because it retrieves the Child Theme directory.
Yes I know the name of the function "get_stylesheet_directory()" is not very intuitive but it it actually will return the Child Theme directory location.
It took a while to work this out by searching online. I found this reference online that helped me in my search: How to override a parent file in a child Wordpress theme when parent file is being required in functions.php