Skip to content

Instantly share code, notes, and snippets.

@bartoszgadomski
Last active December 13, 2023 16:49
Show Gist options
  • Save bartoszgadomski/bae699448ae06416e26440ffce4d9981 to your computer and use it in GitHub Desktop.
Save bartoszgadomski/bae699448ae06416e26440ffce4d9981 to your computer and use it in GitHub Desktop.
<?php
/**
* Randomize theme background colors
*/
add_filter(
'wp_theme_json_data_theme',
/**
* Filter the theme JSON data
*
* @param \WP_Theme_JSON_Data $theme_json The theme.json data class object to access and update the underlying data.
*
* @return \WP_Theme_JSON_Data Same instance as provided.
*/
function ( \WP_Theme_JSON_Data $theme_json ): \WP_Theme_JSON_Data {
$colors = [
'#8D6A9F',
'#C5CBD3',
'#8CBCB9',
'#DDA448',
'#BB342F',
];
return $theme_json->update_with(
[
'version' => 2,
'styles' => [
'color' => [
'background' => $colors[ wp_rand( 0, count( $colors ) - 1 ) ],
],
],
],
);
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment