Site logo

[Resolved] Customizing GenerateBlocks Color Palette

Home Forums Support [Resolved] Customizing GenerateBlocks Color Palette

Home Forums Support Customizing GenerateBlocks Color Palette

Viewing 15 posts - 1 through 15 (of 27 total)
  • Author
    Posts
  • #1200123
    Bodie

    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!

    #1200829
    Tom
    Lead Developer
    Lead Developer

    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 ๐Ÿ™‚

    #1200880
    Bodie

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

    #1201105
    Tom
    Lead Developer
    Lead Developer

    I don’t think so ๐Ÿ™‚

    #1207017
    Mark

    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.

    #1207611
    Tom
    Lead Developer
    Lead Developer

    In GenerateBlocks, or in general?

    #1221872
    Mark

    I will be using Generateblocks mainly.

    #1222436
    Tom
    Lead Developer
    Lead Developer

    As of right now it’s not possible, but I’ll see what I can do ๐Ÿ™‚

    #1222445
    Mark

    Thanks Tom ๐Ÿ˜€

    #1222854
    Tom
    Lead Developer
    Lead Developer

    No problem, thanks for the feedback! ๐Ÿ™‚

    #1251895
    Mike

    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' );

    #1297565
    Matthias

    thx all.

    Was just asking myself this – and here we already got a solution ๐Ÿ˜€

    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.

    #1298369
    Tom
    Lead Developer
    Lead Developer

    Not too sure what you mean – can you explain a bit more? ๐Ÿ™‚

    #1298557
    Matthias

    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.

    #1299531
    Tom
    Lead Developer
    Lead Developer

    The above code (https://generatepress.com/forums/topic/customizing-generateblocks-color-palette/#post-1200829) just makes it so the color palette options you have when using the color picker match what you’ve set. Can be useful if you’re always selecting the same colors.

Viewing 15 posts - 1 through 15 (of 27 total)
  • You must be logged in to reply to this topic.