Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save nextab/ca7a4adff87a0b92d6cdc1b0a41c81a1 to your computer and use it in GitHub Desktop.

Select an option

Save nextab/ca7a4adff87a0b92d6cdc1b0a41c81a1 to your computer and use it in GitHub Desktop.
/**
* Remove bloated inline core color styles.
*
* @param \WP_Theme_JSON_Data $theme_json Class to access and update the underlying data.
*
* @return \WP_Theme_JSON_Data
*/
add_filter(
'wp_theme_json_data_default',
function( $theme_json ) {
$data = $theme_json->get_data();
// If you want to debug, use echo '<!-- nxt debug --><pre>'; print_r($theme_json); echo '</pre>';
// Remove default color palette.
$data['settings']['color']['palette']['default'] = [];
// Remove default duotone.
$data['settings']['color']['duotone']['default'] = [];
// Remove default gradients.
$data['settings']['color']['gradients']['default'] = [];
// Remove shadow presets.
$data['settings']['shadow']['presets']['default'] = [];
// Note: With this method, you can only overwrite "settings", not "styles" or other sub fields of the array, e.g. $data['styles']['elements']['button']['color'] = [];
// Update the theme data.
$theme_json->update_with( $data );
return $theme_json;
}
);
#endregion Clean Up WordPress
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment