最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to "remove" file from parent theme

programmeradmin2浏览0评论

I am having an issue with a theme I am using.

The parent theme has created a woocommerce.php file. When this file exists, it takes precedence over the woocommerce hooks, and it causes issues when I want to use hooks to add content before the woocommerce content.

Is it possible for a child theme to declare that the woocommerce.php file from parent should be ignored ?

I am having an issue with a theme I am using.

The parent theme has created a woocommerce.php file. When this file exists, it takes precedence over the woocommerce hooks, and it causes issues when I want to use hooks to add content before the woocommerce content.

Is it possible for a child theme to declare that the woocommerce.php file from parent should be ignored ?

Share Improve this question asked Jan 30, 2018 at 14:02 MartinMartin 1033 bronze badges 5
  • 1 What happens if you put a woocommerce.php file in the child theme? – Tom J Nowell Commented Jan 30, 2018 at 14:52
  • It will override the parent one, but it means that if any update comes to the parent theme, I won't get it, or I will have to update this file (I guess it's not that bad, and updates are not likely to be that often). – Martin Commented Jan 30, 2018 at 15:12
  • Then could you not include it in your child themes file, then unhook the stuff you don't want? – Tom J Nowell Commented Jan 30, 2018 at 16:18
  • This is the issue, the child theme contains only 2-3 files. If I don't include it in the child, the parent one will be taken. If I create a new one in the child, it will be used by woocommerce, and it is the one that will be used for layout, which means I still won't have the required hooks and default woocommerce behavior. – Martin Commented Jan 30, 2018 at 19:44
  • Just include it: require( get_template_dir().'/woocommerce.php' ); then remove_action and remove_filter your way to success – Tom J Nowell Commented Jan 30, 2018 at 19:54
Add a comment  | 

1 Answer 1

Reset to default 0

The child theme could just delete the parent theme file if it exists (via child theme functions.php). eg.

$template = get_template_directory().'/woocommerce.php'; 
if (file_exists($template)) {unlink($template);}

That would continue to override it if it came to exist again (ie. after a parent theme update.) If you aren't going to update the parent theme just delete it's woocommerce.php

If it's a file other than the WooCommerce files and just another file in the parent theme, copy it into the child theme and remove it's content just leave the <?php ?> tags if the content of the file is not needed.

发布评论

评论列表(0)

  1. 暂无评论