WordPress: How to overwrite a sub-file in a Child Theme

What if we want to override a file in a sub-folder of a Parent Theme in our Child Theme?

Cloning the paths and doing our edits won’t cut it, because functions.php on our Parent Theme will take priority.
We need to tell our Child’s functions.php to include the Child file.

However we have to do it the right way. This methods aren’t enough:


In both cases we’ll still see the Parent’s theme-subfile.php taking priority. This happens because those functions get the Parent Theme’s path, and not the Child’s.

To work around this situation, we’ll have to include the sub-file this way in our Child Theme’s functions.php:

However, we can still find a “Cannot redeclare” error if the Parent theme has no “if function exists” declaration.
As we don’t want to edit the Parent Theme, we have two options:

– we rename the function, paste it on the Child functions.php, and we edit the template file where that function appeared, uploading it to the Child Theme’s folder.

– we remove the original function, register a new function, and hook it.

More clues here!: https://wordpress.stackexchange.com/questions/159403/include-files-in-child-themes-declare-in-functions-php

That’s it, we just edited and correctly included a sub-file in our Child Theme!

17 people super-liked this.

Leave a Reply

Your email address will not be published. Required fields are marked *