0

I'm new to Wordpress and how Child themes work. My child theme I am trying to overwrite two files in sub-directories. I've copied the parent files and edited them in child theme but changes are not reflected in parent theme. I'm trying to change the code for feature image sizes. I successfully changed the code in parent to test it and it works. But child theme isn't overriding it.

/public_html/wp-content/themes/sahifa/framework/functions/theme-functions.php    
/public_html/wp-content/themes/sahifa-child/framework/functions/theme-functions.php
/public_html/wp-content/themes/sahifa/framework/parts/related-posts.php
/public_html/wp-content/themes/sahifa-child/framework/parts/related-posts.php
  1. Other question I had was do I need all the files in each folder to copied over?
  2. Or Can I have the folder and just the one file I'm editing inside?

Update: I have no clue how to add the code by some suggestion made. I'd Appreciate if I could be shown. Here's a link to the files on my Google Drive:

https://drive.google.com/file/d/1xDx62NxDIj3HlEkh3_txZa4mywW-2SlP/view?usp=sharing

https://drive.google.com/file/d/127oDdNQWxritIVXcvbHURANg5b4tpJCL/view?usp=sharing

Update: I see in the parent theme this line of code in the functions.php file:

// Main Functions
require_once ( get_template_directory() . '/framework/functions/theme-functions.php');
2

1 Answer 1

1

If the php file is gets included or required from functions.php file in parent theme all codes are added to runtime they are not replaced if you create files in similar directory structure.

So, What can be replaced?

  1. Only files called via get_template_part() can be replaced this way. This is also true for any file in template hierarchy

  2. If the parent theme uses add_action() or add_filter() with function name you can remove them using remove_action() or remove_filter() and use your own replacements.

  3. If parent theme uses function_exists() or class_exists() with an if encapsulating a function/class they can be replaced from your child themes functions.php file.

7

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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