Site logo

Archived topic

Customizing GenerateBlocks Color Palette

26 replies · Started by Bodie on March 19, 2020

Viewing posts 1–15 of 27

I love the ability to customize the GeneratePress color palette and I was wondering if there was a way to do the same with the GenerateBlocks color palette? Assuming you could do something the same as here:

add_filter( 'generate_default_color_palettes', 'tu_custom_color_palettes' );
function tu_custom_color_palettes( $palettes ) {
	$palettes = array(
		'#000000',
		'#FFFFFF',
		'#F1C40F',
		'#E74C3C',
		'#1ABC9C',
		'#1e72bd',
		'#8E44AD',
		'#00CC77',
	);
	
	return $palettes;
}

Not sure what hooks exist in GenerateBlocks yet, so thought I would check here first.

Thanks!

Hi there,

Gutenberg itself has a way to define the colors:

add_action( 'after_setup_theme', function() {
    add_theme_support( 'editor-color-palette', array(
        array(
            'name'  => __( 'Blue' ),
            'slug'  => 'blue',
            'color' => '#59BACC',
        ),
        array(
            'name'  => __( 'Green' ),
            'slug'  => 'green',
            'color' => '#58AD69',
        ),
        array(
            'name'  => __( 'Orange' ),
            'slug'  => 'orange',
            'color' => '#FFBC49',
        ),
        array(
            'name'  => __( 'Red' ),
            'slug'  => 'red',
            'color' => '#E2574C',
        ),
    ) );
} );

Let me know if you need more info :)

Great! Thanks Tom for the quick response. Is there a limit to how many colors can be added?

I don't think so :)

Brilliant, exactly what i was looking for. Is there a way to disable custom color in Gutenberg. So that clients can't pick outrageous colors, they can just choose from the color palette that i give them.

In GenerateBlocks, or in general?

I will be using Generateblocks mainly.

As of right now it's not possible, but I'll see what I can do :)

Thanks Tom 😀

No problem, thanks for the feedback! :)

Actually, you can disable custom colors in the gutenberg palette, add this just before the other add_theme_support:
add_theme_support( 'disable-custom-colors' );

thx all.

Was just asking myself this - and here we already got a solution :D

But i am a bit confused now if those two solutions can be merged into one? So you dont have to add each color twice.

Not too sure what you mean - can you explain a bit more? :)

i mean if it is possible to combine the two code blocks - so you only need to enter the palette one time in your css - and it shows in back (gutenberg) and frontend (customizer).

not really sure where to place mikes code best also.

This archived topic is closed to new replies.