问题
I'm building my first child theme. My child theme is my active theme at the moment. So, I have a file under the parent theme which is at wp-content/themes/mytheme/template-parts/ajax-mytick-list.php
and I copied it to wp-content/themes/mytheme-child/template-parts/ajax-mytick-list.php
and edit it there. But the site is not showing the one that I edited under child theme. Cos if I edit the same file in parent theme, the result is reflected.
What am I doing wrong?
回答1:
You can override page templates this way, but not other files. In this case, you'll need to override the according function (guide) or hook into it with an action hook or filter.
More details according to your question below: You'll need to find out where the template-parts file is getting included. Search the parent theme for something like
require get_template_directory() . '/template-parts/ajax-mytick-list.php';
If that call is in a template file, copy it to your child theme and change the call to
require get_stylesheet_directory() . '/template-parts/ajax-mytick-list.php';
If it's not in a page template, you'll need to dig deeper, but as every theme is different, it's impossible to say how exactly you'll get there.
来源:https://stackoverflow.com/questions/57495702/child-theme-doesnt-read-template-part-file