0

I'm about to build a new site based on a theme close to what I'm looking for. I understand the concepts around child theming & have read the caveats about overriding php or css files like the one described here.

Using such workarounds and calls from functions.php, is it possible to build a "Frankenchild theme" by taking chunks of a second (would-be parent) theme and patching them into the child theme? I'm not quite asking about creating a child of two parents; the child would only have one "official" parent.

As an example: Start with a Gantry basic theme and add custom taxonomy search capabilities & search results formatting (say a card-based carousel). Is that stepping over the line into plugin development?

3
  • Do you mean copying the functionality of a 3rd theme into the child theme folder? Or do you mean a child theme that require/include's files of a 3rd theme installed on the site that is neither the parent of child theme?
    – Tom J Nowell
    Apr 12, 2021 at 18:20
  • You got me there - my thought was about copying a 3rd theme into the child theme, but I'll have to read up about require and include... thank you for that tip. Apr 12, 2021 at 18:40
  • 1
    I would not recommend doing that, do not consider my mention of require/include as a tip, but rather a warning. loading files from a non-active theme should be considered extreme bad practice
    – Tom J Nowell
    Apr 13, 2021 at 9:28

2 Answers 2

0

The canonical answer is that themes are for visuals only, the rest go in plugins.

In practice though, people bundle everything in a theme because it's easier to sell a zip you upload to the themes folder. In the future it will be possible to have themes that contain little to no PHP at all thanks to full site editing.

With that in mind, if you want to take functionality from an unrelated theme, nothing prevents you copying the files over, however, this doesn't mean that it will work. You'll almost certainly need to make adjustments so that styling looks right. You may need to implement PHP and JS changes to restore the functionality.

If you can move it to a plugin then that should always be the preferred choice.

If at any point you are tempted to load the code directly from the other themes folder via include or require, do not do this. It is extreme bad practice, and a very bad thing to do. There is no situation where this is a good idea. Avoid at all costs.

2
  • Starting to understand that adding parts of other themes to the child theme would be a job of accounting for all the dependencies that would need to be modified. I guess this would only be worthwhile if the same functionality couldn't be achieved with plugins and then adding css & perhaps php functions as tweaks if necessary. Thanks - a lot of this will probably be more clear with more familiarity with the Codex. Honestly the WP documentation is among the best I've seen; surprised I don't see more answers like "read the Codex." ;) Apr 14, 2021 at 1:32
  • 1
    if you like the codex you'll love the developer handbooks developer.wordpress.org
    – Tom J Nowell
    Apr 14, 2021 at 8:35
0

That article you referenced is more or less about calling to something if it existed. That's fine when you are using plugins or functions that need to be called, however that's not the most important part of using a child theme.

The reason you would want to use a child theme is to add custom coding. You cannot use functions or snippets per se from the Parent. Adding snippets from a parent would render an error by calling a function twice.

The best approach is to make a plan and hook in your custom code to create Frankenstein child theme needs.

It's best to list your requirements of why you even need the child theme? What custom code are you going to need to add?

2
  • Thanks - my idea was to take code and/or (parts of) page templates from a second theme, adapting them to work with the actual parent theme. I'm understanding that this is probably not necessary in most cases. Apr 14, 2021 at 1:27
  • 1
    If I understand you correctly then you'll want to copy parent templates to the child in order to customize them the way you want. Then add hooks wherever possible. That's the appropriate way and best solution when using a child theme. Apr 14, 2021 at 20:10

Your Answer

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

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