Skip to content

Instantly share code, notes, and snippets.

@karpstrucking
Created April 25, 2015 10:21
Show Gist options
  • Save karpstrucking/ec8e7de6b6f570f38ab8 to your computer and use it in GitHub Desktop.
Save karpstrucking/ec8e7de6b6f570f38ab8 to your computer and use it in GitHub Desktop.
Copy parent theme's mods to child theme on activation
<?php
add_action( 'after_switch_theme', 'gowp_copy_theme_mods' );
function gowp_copy_theme_mods() {
$mods = get_theme_mods();
if ( is_null( $mods ) || ( ( 1 == count( $mods ) ) && ! $mods[0] ) ) {
$parent = wp_get_theme()->get('Template');
$child = basename( dirname( __FILE__ ) );
update_option( "theme_mods_$child", get_option( "theme_mods_$parent" ) );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment