Move or copy patterns to child theme

;TL/DR; Can we migrate block patterns with all required styling and media dependencies to a child theme?

The detail…

We created patterns in the TT3 theme and then decided changes in Style Variations were desired, or rather a copy/edit of a json file in the styles folder. It was clear that a Child theme was required for this and ongoing customizations.

So I used the standard WP Export which looks like it will do the job. I created a Child theme and switched to it.

The custom patterns are not in the Child theme when that is activated. My guess is that the patterns are in the database, keyed to the parent name. And I probably need an enqueue hook that directs the Child to use the Parent key when referencing patterns.

Then again, if a child theme changes beyond basics, we don’t want it to use parent patterns. So, this is where I figured the Export would help.

But while it looks from the Export text that patterns might be included, the text for Import doesn’t give the same impression. It makes sense that a block structure can include blocks that are unique to an environment, not available in a new one for import. A pattern can rely on style variations and media that aren’t available in a new environment, so why bother to import them?

That makes me think I’m just using the wrong tool. The classic Export/Import does a lot more than in the past but maybe this is not one of the features.

That leaves the question, what is the right tool to export and import blocks, patterns, template parts, and templates … in the same environment? … Or at least from parent theme to child?

Apparently now I need to create a separate environment to test what was originally just another website using blocks. The challenge will be to recreate a TT3 child, Export patterns from parent, Import to child, and see what’s missing …and find other tools to test their efficacy.

( Gawd, I love all of this technology that makes our lives easier and saves us so much time. :rolling_eyes: )

The real question is … Where is current documentation about this area so that I can read about how to do this and what to expect? I understand this is FOSS, docs are voluntary and often need to catch up. (I’ve contributed to the docs.) Maybe I missed detail. Maybe there are videos. Maybe WPMU DEV has blogged about this in an oft-labeled “Ultimate Guide”.

As much as seeking answers, I want to know where the answers are or should be. Let’s note here where to fish rather than tossing fish around. ( Ref the “Teach a man to fish” proverb. )

What confounds me is that Gutenberg is evolving, especially with changes just in WP 6.3, and the docs aren’t keeping up. I’ll take that up with the team there. For now, I’m asking here. :smirk:

Thank You!

    • Tony G
      • Mr. LetsFixTheWorld

      Indeed! I was using the wrong tool. The Tools>Export feature is incorrect. The correct tool seems to be in “/edit.php?post_type=wp_block”. However…

      It looks like we need to export and import each individual pattern as JSON. Yes, I’m getting greedy now … Is there (yet) a feature to export all into a collection (zip) and then import them all back?

      I’m sure now that this can be done with code. I would just need to look at the API to make it happen. (Hmm, sounds like a useful plugin until it’s built-in to core.) For my immediate purposes however, it would take longer to write such code than to manually export/import the …um… 17 patterns that I face for the immediate challenge.

      The link was good, thank you very much – you pointed to the fish. :slight_smile: :fishing_pole_and_fish: :fish:

      I will continue to search for info about exactly where and how patterns are saved and keyed to a theme. I know they’re just CPTs of type ‘wp_block’. I’d like to understand how to reuse them across themes (parent>child). The solution to this might be to add a theme name to an array, or to copy the post object and change the theme key. Either of these would be a simple SQL operation – no plugin required. I’ll post back here when I get this info.