How to let customized php working in child theme

I have customized the php of inc/slider.php.
To avoid to be overwritten by update. I create a sydney child theme.
I activated the child theme, but the slider.php doesn’t work for new child theme.
How can I do?

Hello there,

I am afraid this file can’t be overridden in the child theme. Because it isn’t part of the native WordPress template hierarchy. It’s actually a custom template file. You can override the sydney_slider_template() function in your child theme’s functions.php file as it is a pluggable function.


So, my bad. I didn’t describe things clearly.
You misunderstand my meaning.
I customized slider.php in theme/sydney/inc.
I found it will be overwritten by theme update.
Now, I think to use child theme to avoid the overwritten.
I just copy my customized php to theme/sydney-child, but it doesn’t work.
What is the correct place to place the customized php file in child theme folder or what else I need to do?

Hello there,

I am afraid there is no way to do that. The slider.php file is loaded in the parent theme only by using the get_template_directory() function. This function doesn’t allow child themes to overwrite it. Try the following alternative solution (you will still touch the parent theme file, though):

  1. Open the parent theme’s functions.php file
  2. Comment out this line require get_template_directory() . '/inc/slider.php';. So you will have something like this

// require get_template_directory() . '/inc/slider.php';

  1. Put this line in the child theme’s functions.php file

require get_stylesheet_directory() . '/inc/slider.php';

  1. Copy sydney/inc/slider.php to sydney-child/inc/slider.php

I hope it helps.