Repository navigation
fix(child-theme): Preserve navigation block refs when creating a child theme - #882
Open
KarunyaChavan wants to merge 2 commits into
Open
KarunyaChavan wants to merge 2 commits into
KarunyaChavan wants to merge 2 commits into
Conversation
- Pass template options with removeNavRefs set to false to add_templates_to_local() in create_child_theme() - Prevent unconditional stripping of ref attributes from core/navigation blocks in child theme templates - Avoid navigation collisions where distinct menus fall back to the same menu resolution - Align child theme template export options with the pattern used in clone_current_theme()
- Add test_not_eliminate_nav_block_ref_nested_with_template_options test case - Assert that nested navigation blocks retain their ref attribute when removeNavRefs is false
KarunyaChavan
marked this pull request as ready for review
October 5, 2026 08:54
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes a bug where navigation block
refattributes were unconditionally stripped from all template parts when using the "Create child theme" feature, causing distinct header and footer menus to collapse into the same fallback menu after the child theme was activated.Fixes #866
Why?
create_child_theme()method in [includes/create-theme/theme-create.php] calledCBT_Theme_Templates::add_templates_to_local()without passing any$options, causing$optionsto benullall the way down the call chain.eliminate_environment_specific_content_from_block(), when$optionsisnull, the guard condition! $optionsis truthy and therefattribute is always removed - regardless of user intent.{"ref": 224}) and the footer navigation block ({"ref": 229}) were exported with therefstripped, causing WordPress core to trigger its fallback resolution and render both navigation areas using the same menu.clone_current_theme()method in the same file has always passed explicit options ('removeNavRefs' => false) and was not affected. The child theme code path was simply never updated whenremoveNavRefswas introduced.What Changed?
includes/create-theme/theme-create.php-create_child_theme():$template_optionswithremoveNavRefs => false,localizeText => false, andlocalizeImages => false.$template_optionsas the 4th argument toCBT_Theme_Templates::add_templates_to_local().clone_current_theme().tests/test-theme-templates.php-Test_Create_Block_Theme_Templates:test_not_eliminate_nav_block_ref_nested_with_template_optionsto assert that a navigation block nested inside a group block retains itsrefattribute whenprepare_template_for_export()is called withremoveNavRefs => false.test_not_eliminate_nav_block_reftest (which only covers a top-level navigation block with a partial options array).Steps for Testing
Setup:
Reproduce the bug (on
trunkbefore this PR):Header Menu). Save.Footer Menu). Save.parts/header.htmlandparts/footer.htmlin the new child theme folder:<!-- wp:navigation {"ref":X,...} /-->-refpreserved.<!-- wp:navigation /-->-refstripped.Verify the fix (on this branch):
header.htmlshould contain"ref":<header-menu-id>.footer.htmlshould contain"ref":<footer-menu-id>.Use of AI