Created
June 14, 2026 05:51
-
-
Save arfinmilondev/aca64efccb8fb7635815921bfb574220 to your computer and use it in GitHub Desktop.
Migrate Theme Customizations (Theme Mods) from Parent to Child.
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
| <?php | |
| /** | |
| * Migrate Theme Customizations (Theme Mods) from Parent to Child. | |
| * | |
| * WordPress stores Customizer settings separately for each theme based on folder name. | |
| * When switching to a child theme, settings seem to reset. This function automatically | |
| * copies those settings from the parent theme 'hello-shoppable' exactly once. | |
| */ | |
| function hello_shoppable_child_migrate_theme_mods() { | |
| if ( ! get_option( 'hello_shoppable_child_mods_migrated' ) ) { | |
| $parent_mods = get_option( 'theme_mods_hello-shoppable' ); | |
| if ( ! empty( $parent_mods ) ) { | |
| foreach ( $parent_mods as $key => $value ) { | |
| set_theme_mod( $key, $value ); | |
| } | |
| } | |
| // Set option flag to prevent re-running on subsequent page loads | |
| update_option( 'hello_shoppable_child_mods_migrated', true ); | |
| } | |
| } | |
| add_action( 'after_setup_theme', 'hello_shoppable_child_migrate_theme_mods' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment