Skip to content

Instantly share code, notes, and snippets.

@robincornett
Created October 16, 2019 12:57
Show Gist options
  • Save robincornett/29099d3ba7a2770f686c972eb51ca05d to your computer and use it in GitHub Desktop.
Save robincornett/29099d3ba7a2770f686c972eb51ca05d to your computer and use it in GitHub Desktop.
Add the editor color palette to your site using wp_inline_style
<?php
add_action( 'enqueue_block_assets', 'rgc_editor_color_palette', 15 );
/**
* Add custom colors to the site using wp_inline_style, attached to the wp-block-library stylesheet.
* Colors must be defined in your theme or functionality plugin.
*/
function rgc_editor_color_palette() {
list( $colors, ) = (array) get_theme_support( 'editor-color-palette' );
if ( ! $colors ) {
return;
}
$css = '';
foreach ( $colors as $color ) {
$css .= sprintf(
'.has-%1$s-color {color: %2$s;} .has-%1$s-background-color {background-color: %2$s;} ',
$color['slug'],
$color['color']
);
}
wp_add_inline_style( 'wp-block-library', $css );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment