Skip to content

Instantly share code, notes, and snippets.

@seothemes
Created October 20, 2022 01:14
Show Gist options
  • Save seothemes/0396a90533d1d74c7ec54b07554d31eb to your computer and use it in GitHub Desktop.
Save seothemes/0396a90533d1d74c7ec54b07554d31eb to your computer and use it in GitHub Desktop.
Merge parent theme style variation with active child theme
<?php
add_filter( 'theme_json_theme', 'get_parent_theme_style_variation_data' );
/**
* Merges parent theme style variation data with active theme.json.
*
* @since 1.0.0
*
* @param mixed $theme_json WP_Theme_JSON_Data | WP_Theme_JSON_Data_Gutenberg.
*
* @return mixed
*/
function get_parent_theme_style_variation_data( $theme_json ) {
$parent_style_variation = get_template_directory() . '/styles/dark-mode.json';
$parent_style_json = json_decode( file_get_contents( $parent_style_variation ), true );
return $theme_json->update_with( $parent_style_json );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment