Created
October 16, 2019 12:57
-
-
Save robincornett/29099d3ba7a2770f686c972eb51ca05d to your computer and use it in GitHub Desktop.
Add the editor color palette to your site using wp_inline_style
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 | |
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