1

I'm trying to customise the Storefront theme from WooCommerce, by creating a child-theme. I've already done a couple of things in the 'functions.php' file, but I can't seem to overwrite the 'require' in the parent.

In my child-theme's 'functions.php' I'm trying to overwrite the file it requires in the parent's 'functions.php'. Unfortunately, when I do this, it keeps showing the required file the parent called for.

Below is the line of code I've tried:

require '/inc/storefront-template-hooks.php';

&

require get_template_directory() . '/inc/storefront-template-hooks.php';

What am I doing wrong?

  • 4
    A functions file in a child theme does not override the functions from the parent theme, but adds them. So the file in the parent theme is always loaded (afaik). I see that the parent theme file has nothing but add_actions. What you can do is first 'undo/delete these actions (by a hook) and then add your own. – Beee Feb 23 '18 at 23:52
  • As Beee says, child themes add to, rather than replace, so you can't replace an included file from the parent theme. However, as that particular file is just setting up a load of action hooks, you can look at what it's doing and add remove_action() lines to your functions.php to unhook those that you don't want. For example, in the file is add_action( 'storefront_footer', 'storefront_credit', 20 ); so you can have remove_action( 'storefront_footer', 'storefront_credit', 20 ); and, voila, no more footer credit! – Peter HvD Feb 26 '18 at 12:22
-2

according to the documentation https://codex.wordpress.org/Function_Reference/get_template_directory

If a child theme is being used, the absolute path to the parent theme directory will be returned. Use get_stylesheet_directory() to get the absolute path to the child theme directory.

I hope you find it useful :)

  • As Beee commented in the question, child theme does not override the functions from the parent theme. Your answer is irrelevant. – Akshat May 23 '18 at 16:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.