Skip to content

Instantly share code, notes, and snippets.

@cameronjonesweb
Last active October 7, 2020 23:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cameronjonesweb/1ffbfca7563a787fd59a000f9746b86f to your computer and use it in GitHub Desktop.
Save cameronjonesweb/1ffbfca7563a787fd59a000f9746b86f to your computer and use it in GitHub Desktop.
<?php
function cameronjonesweb_colour_scheme() {
return array(
array(
'name' => 'White',
'slug' => 'white',
'color' => '#ffffff',
),
array(
'name' => 'Black',
'slug' => 'black',
'color' => '#222222',
),
array(
'name' => 'Grey',
'slug' => 'grey',
'color' => '#f4f4f4',
),
);
}
/**
* Generate CSS rules for the colour scheme
*
* @return string
*/
function cameronjonesweb_generate_colour_scheme_styles() {
$colours = cameronjonesweb_colour_scheme();
$styles = '';
if ( ! empty( $colours ) ) {
foreach ( $colours as $colour ) {
$styles .= sprintf(
'.has-%1$s-color { color: %2$s; } .has-%1$s-background-color { background-color: %2$s; }',
$colour['slug'],
$colour['color']
);
}
}
return $styles;
}
/**
* Render style tag with the colour scheme styles
*/
function cameronjonesweb_render_colour_scheme_styles() {
wp_add_inline_style( 'wp-block-library', cameronjonesweb_generate_colour_scheme_styles();
}
add_action( 'init', 'cameronjonesweb_render_colour_scheme_styles' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment