Monthly Archives: June 2016

You are here: Home . Archive

WordPress Child theme – Inheriting parent options

When building a WordPress child theme, it’s important for it to, at least initially, pick-up the settings from the parent theme.

Here’s something that works to allow your child theme to, on activation, retrieve the parent’s theme options:

add_action( 'after_switch_theme', 'themeprefix_switch_theme_update_mods' );

function themeprefix_switch_theme_update_mods() {

if ( is_child_theme() && false === get_theme_mods() ) {

$mods = get_option( 'theme_mods_' . get_option( 'template' ) );

if ( false !== $mods ) {

foreach ( $mods as $mod => $value ) {

if ( 'sidebars_widgets' !== $mod )//Leave out the sidebars
set_theme_mod( $mod, $value );
}
}
}
}

Note that there’s still an unresolved WordPress ticket to have this feature added to core: WordPress Ticket #27177
Code credit: @greenshady