Site logo

Archived topic

Theme support declaration not working after 3.1.0 update.

3 replies · Started by Lewis on October 27, 2021

Viewing posts 1–4 of 4

Hey there,

I was initially using theme support to change some basic Gutenberg features before the 3.1.0 update. These functions, however, now cease to work and I think are being overridden by GP?

Could you provide guidance on this? Is it possible to set global colours using functions.php? (I prefer this as it's a little quicker.)

Here's the code I have installed on a number of sites; it's going to be a pain to fix them all.

functions.php

/**
 * colour palette customisation (WP)
 */
add_filter('generate_default_color_palettes', 'tu_custom_color_palettes');
function tu_custom_color_palettes($palettes)
{
    $palettes = array(
        '#23a455',
        '#156534',
        '#040f0f',
        '#666666',
        '#f8f8f8',
        '#ffffff',
        '#000000'
    );
    
    return $palettes;
}

add_action('after_setup_theme', 'colors_after_setup_theme');
function colors_after_setup_theme() {
	
	/* Colors theme support */
	add_theme_support('editor-color-palette', array(
		array(
			'name' => __('Green', 'generatepress'),
			'slug' => 'green',
			'color' => '#23a455'
		),
		array(
			'name' => __('Cadmium Green', 'generatepress'),
			'slug' => 'cadmium-green',
			'color' => '#156534'
		),
		array(
			'name' => __('Rich-Black', 'generatepress'),
			'slug' => 'rich-black',
			'color' => '#040f0f'
		),
		array(
			'name' => __('Muted Grey', 'generatepress'),
			'slug' => 'muted-grey',
			'color' => '#666666'
		),
		array(
			'name' => __('Ghost White', 'generatepress'),
			'slug' => 'ghost-white',
			'color' => '#f8f8f8'
		),
		array(
			'name' => __('White', 'generatepress'),
			'slug' => 'white',
			'color' => '#ffffff'
		),
		array(
			'name' => __('Black', 'generatepress'),
			'slug' => 'black',
			'color' => '#000000'
		)
	)); 
	
}

CSS


/** Custom colours for Gutenberg editor **/
/** =================================== **/

/* Colors */
.has-green-background-color {
	background-color: #23a455;
}
.has-green-color {
	color: #23a455;
}
.has-cadmium-green-background-color {
	background-color: #156534;
}
.has-cadmium-green-color {
	color: #156534;
}
.has-rich-black-background-color {
	background-color: #040f0f;
}
.has-rich-black-color {
	color: #040f0f;
}
.has-muted-grey-background-color {
	background-color: #666666;
}
.has-muted-grey-color {
	color: #666666;
}
.has-ghost-white-background-color {
	background-color: #f8f8f8;
}
.has-ghost-white-color {
	color: #f8f8f8;
}
.has-white-background-color {
	background-color: #ffffff;
}
.has-white-color {
	color: #ffffff;
}
.has-black-background-color {
	background-color: #000000;
}
.has-black-color {
	color: #000000;
}

Hi there,

You should just need to add a higher priority to your after_setup_theme hook:

add_action('after_setup_theme', 'colors_after_setup_theme', 20);

Hope this helps :)

@Tom, you sire' are amazing and I'm an idiot. 😅

Not at all! We just defined our own palette in 3.1, so you just had to bump your priority a little.

Glad I could help :)

This archived topic is closed to new replies.