Last active
December 13, 2023 16:49
-
-
Save bartoszgadomski/bae699448ae06416e26440ffce4d9981 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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