blog-limit-colours

Add a Custom Colour Pallet to Gutenberg

Published: 28th November 2018

The new WordPress editor is making it very easy for users to change the colour of various elements but is this a good idea?

We’ve already discussed how the new editor comes with blocks and how to limit these in our article Limiting Blocks Within Gutenberg. In this article we want to look at controlling which, if any, colours clients can use within their written content.

We design our websites very carefully, taking into consideration the brand, user experience and user interface. We establish a colour palette that is used throughout the website which is on brand and ensures a smooth user journey. For example, making interactive elements such as buttons a particular colour re-enforces the fact that they are there to be clicked. This carefully thought out pallet is defined by the CSS within the theme.

The WordPress editor has always had the ability to change text colour, but Gutenberg has taken this further, making the option to do so more obvious and including tools to change the background colour of elements. That’s an awful lot of control to give clients, the power to overwrite theme CSS and experiment with an unlimited pallet of colours as they see fit, this can quickly break the design.

We’re not ready to have our Design, Development and Marketing experts shouting at us because a client has overwritten the CSS, set the font colour to yellow, added a pink background which  outshines (for all the wrong reasons) the CTAs that were put in place! As such, we’ve put together some code snippets which should help! All of these can be placed within the functions.php file.

Prevent Custom Colours

By default clients will be able to select any colour they like from the colour wheel, let’s remove this functionality in favour of setting our own colours later.

function theme_disable_custom_colors() {
add_theme_support( 'disable-custom-colors' );
}
add_action( 'after_setup_theme', 'theme_disable_custom_colors' );

Define a New Colour Palette

If we’re going to give clients the ability to change colours it makes sense for designers to pre-define these to ensure they compliment the overall design as much as possible. This snippet will allow us to do just that, you can see we’ve set 3 colours from our own branding.

function theme_color_palette() {
	add_theme_support(
		'editor-color-palette', array(
			array(
				'name'  => esc_html__( 'Orange', '@@textdomain' ),
				'slug' => 'orange',
				'color' => '#f37557',
			),
			array(
				'name'  => esc_html__( 'Blue', '@@textdomain' ),
				'slug' => 'blue',
				'color' => '#3aadb4',
			),
			array(
				'name'  => esc_html__( 'Grey', '@@textdomain' ),
				'slug' => 'grey',
				'color' => '#454548',
			)
		)
	);
}
add_action( 'after_setup_theme', 'theme_color_palette' );

Disable All Colours

If we’re still not comfortable giving clients the ability to change colours we can remove this altogether!

function theme_disable_all_colors() {
        add_theme_support( 'editor-color-palette' );
	add_theme_support( 'disable-custom-colors' );
}
add_action( 'after_setup_theme', 'theme_disable_all_colors' );

In Summary

As in our previous article, we’re excited to see where Gutenberg takes us and how much value it can add to the WordPress editing experience. With simple snippets such as those above we can limit functionality that might not be ideal but also enhance useful features.


Previous Page

More blog entries

Limiting Available Blocks Within Gutenberg

Published: 26th November 2018

We're not against change, but after looking at the new editor we were concerned at just how much it allows site admins to do. With so many blocks to choose from and in a limitless combination clients...

Read the full article

Are You Gettin’ Ready For Gutenberg?

Published: 20th November 2018

Wordpress has had the same editor for as long as we can remember, it's had a few features added or removed over the years but otherwise it's always worked and looked the same. This has made it very...

Read the full article

In Browser Push Notifications – Are you missing out?

Published: 5th November 2018

You’re probably familiar with push notifications on your phone, they pop up to let you know when some activity has occurred within one of your apps or web services. It might be a Facebook post, or...

Read the full article

Get in touch today, let's talk about your next project

Follow us on Twitter

RT @sewatch: There are more than 200 ranking signals used by Google. Here are 14 of the most important ones for 2019. https://t.co/wwisbHD

3 days ago

User Friendly Media
@UFMediaUK

@learnwithmattc We've been running some tests recently and noticed that Gravity Forms breaks the new editor, might be worth checking out? :)

16 days ago

User Friendly Media
@UFMediaUK

Inventory and assessment - what to do with your older blog posts. Thanks @Moz https://t.co/Kl3oTfEE94

17 days ago

User Friendly Media
@UFMediaUK

RT @Designmodo: 10 Websites with Data Visualization Driving User Experience - https://t.co/4Rz2CLwWYG A new showcase on Designmodo. #exa

17 days ago

User Friendly Media
@UFMediaUK

Joomla Development Drupal Development Wordpress Development Shopify Setup and Customisation Laravel Development Boot Strap Framework development Google Street View Integration Cloud Flare Content Distribution