0

I've built a child theme, and I would like to reuse some of the settings created by the parent. I hoped this would be as easy as get_theme_mod( 'setting' ) inside the child theme, but that returns nothing.

I found a feature request that addresses this very thing which leads me to believe WP doesn't offer an easy way to get to those parent theme settings. Has anyone found a way around this?

1

If you look at how the code works, you should notice that theme mods are saved in the *_options table under theme_mods_{theme_slug} with the theme slug being, as near as I can tell, the directory name containing the theme stylesheet, so:

$ptheme = get_template_directory();
$theme_slug = basename($ptheme);
$mods = get_option( "theme_mods_$theme_slug");

As a function:

function get_parent_theme_mods($mod = '') {
  $ptheme = get_template_directory();
  $theme_slug = basename($ptheme);
  $mods = get_option( "theme_mods_{$theme_slug}");
  if (!empty($mods) && isset($mods[$mod])) {
    $mods = $mods[$mod];
  }
  return $mods;
}
var_dump(get_parent_theme_mods());
var_dump(get_parent_theme_mods('background_color'));
  • I've implemented this, but it didn't seem to work. Logged all the variables out and found that $mods is empty. $ptheme and $theme_slug are showing the values I expect. – raddevon May 27 '15 at 19:22
  • Have you checked the database itself for those theme mods? – s_ha_dum May 27 '15 at 19:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.