How do I get a parent theme modification from a child theme?

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'));

Leave a Comment