TinyMCE 4 Custom Colour Swatches

How To Add Custom Colours To TinyMCE 4 in WordPress 3.9+

WordPress 3.9 brings up latest TinyMCE 4 rich text editor as grat speed improvement, but this update break a lot of TinyMCE plugins (advanced image, advanced link, etc), including various handy customizations for TinyMCE editor in WP-way.

One of them are custom colour swatches. Until 3.9 we simply put following code to functions.php and got our own colours in editor:

Convert TinyMCE option for custom colour swatches to version 4

This solution will not work in WP 3.9, so we need to replace it with working solution below (to be clear, format of colours array is changed, along to TinyMCE option name):

As you can see, option is changed from theme_advanced_text_colors to textcolor_map, and simple array of HEX codes separated by commas, now is changed to JavaScript array that threat elements as pairs of HEX colour value and colour nice name. All is wrapped to brackets.

Change number of colour swatches

Please note, my default TinyMCE 4 have limit up to 40 colour swatches (80 array elements) distributed in 5×8 grid (ROWSxCOLS). So, to append custom colours after default colours, we need to increase number of rows displayed on swatches popup.

To achieve this, we use textcolor_rows parameter.

We even can change grid layout and alter default 5×8 with, for example, 4×10 by setting parameters below:

Please note, this is just example. You can play with layout and colour set as you wish.

How To Add ‘More Colors’ Functionality?

TinyMCE 4 drop support for ‘More Colors’ option, but now there is WordPress plugin TinyMCE Color Picker that brings back this functionality to WordPress 3.9+

Did this tips helped you?

If you found this tips useful, feel free to 

A question posed to StakOverflow encouraged me to explain how this problem can be resolved quickly and easily.

7 thoughts on “How To Add Custom Colours To TinyMCE 4 in WordPress 3.9+”

  1. This is so great! Thanks for the tip. Beyond this trick, any idea how to add the “More Colors” options to bring up a color picker? So it isn’t limited to the default and custom color additions?

    Thanks for your tips.

  2. Hi Aleksandar
    Because functions.php doesn’t exist in Tinymce-advanced folder I put this code into wp-includes/functions.php and just got error 500.
    Where is location of this file?

      1. I have installed TinyMCE 4.0/WordPress 3.9.
        When I tried first option ‘my_mce3_options’ nothing happened and with second option I got error again. And now I put it into functions.php wich is inside WordPress theme directory.
        Is there another way?

        1. This tip is only for WordPress websites. You can’t use it on non-WordPress system (Joomla, custom CMS, etc).

          So, if you use WordPress, read error messages which you receive with code found in this blog post, and fix reported issues.

Leave a Reply

Your email address will not be published. Required fields are marked *