2

Basically, I'm trying to override some files of the Uncode theme. But this is not a theme-specific question: it can be applied to any theme. The Uncode theme has a custom dir 'partials' (/uncode/partials/) that contains some layout elements. On my child theme I created a 'partials' folder as well (my-child-theme/partials), but the inner files seem not to be overridden. Is it normal? WP docs say that any file of the same name should be overridable, but is seems that's not true. Am I doing something wrong?

2

It depends entirely on the parent theme. While WordPress will check the child theme for templates in the Template Hierarchy and use those if they are present, it's up to theme authors to decide how much overwriting by child themes they want to support for any other files outside this hierarchy.

For example, when including template parts the theme author could use:

require 'partials/partial.php';

And this would work fine, but if the theme author wanted to support child theming they would use:

get_template_part( 'partials/partial' );

This is because get_template_part() will check the child theme for partials/partial.php and use that if it exists, otherwise it will fall back to the parent theme's copy of partials/partial.php.

Since 4.7.0, WordPress has added several functions that allow theme authors to support child theming for other files.

get_theme_file_uri() will return a URL for a file in the child theme if it exists, otherwise it will use the parent themes'. This allows themes to support replacing CSS and JS files in child themes.

For example, if the parent theme enqueues a stylesheet like this:

wp_enqueue_style( 'custom-style', get_theme_file_uri( 'assets/custom.css' ) );

Then a child theme author can replace that stylesheet by just placing assets/custom.css in their child theme.

get_theme_file_path() will return the path for a file in the child theme if it exists, otherwise it will use the parent themes'. This can be used by parent themes to allow child themes to replace entire included PHP files.

For example, if the parent theme included a PHP file like this:

include get_theme_file_path( 'inc/template-tags.php' );

Then a child theme author could replace template-tags.php by just placing inc/template-tags.php in their child theme.

So the takeaway here is that WordPress does support child themes replacing arbitrary files from their parent theme, but the parent theme author needs to explicitly support it by using the correct functions.

Uncode is a paid theme, so I can't see the code, but I suspect it's not using get_template_part(), which is why you can't replace the files in your child theme. Paid themes are often not good 'WordPress citizens' and have pretty spotty support for functionality like this.

| improve this answer | |
0

That is a very good question, the theme directory can be quite confusing sometimes.

The answer is No, WordPress only looks at core theme files. Since a sub directory isn't part of this it will not look for sub folders in your child theme. What you can do is include the file that includes the partials folder, and that will include your custom partials folder in your child theme.

| improve this answer | |

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.