{"id":505,"date":"2014-04-20T16:02:11","date_gmt":"2014-04-20T14:02:11","guid":{"rendered":"https:\/\/urosevic.net\/wordpress\/?p=505"},"modified":"2026-03-10T16:51:25","modified_gmt":"2026-03-10T15:51:25","slug":"custom-colours-tinymce-4-wordpress-39","status":"publish","type":"post","link":"https:\/\/urosevic.net\/wordpress\/tips\/custom-colours-tinymce-4-wordpress-39\/","title":{"rendered":"How To Add Custom Colours To TinyMCE 4 in WordPress 3.9+"},"content":{"rendered":"\n<p>WordPress 3.9 brings up the latest TinyMCE 4 rich text editor as great speed improvement, but\u00a0this update breaks a lot of TinyMCE plugins (advanced image, advanced link, etc), including\u00a0various handy\u00a0customizations for\u00a0TinyMCE editor in WP-way.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>One of them is\u00a0custom colour swatches.\u00a0Until 3.9 we simply put the following code to functions.php and got our colours in the editor:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function my_mce3_options( $init ) {\n$default_colours = '000000,993300,333300,003300,003366,000080,333399,333333,800000,FF6600,808000,008000,008080,0000FF,666699,808080,FF0000,FF9900,99CC00,339966,33CCCC,3366FF,800080,999999,FF00FF,FFCC00,FFFF00,00FF00,00FFFF,00CCFF,993366,C0C0C0,FF99CC,FFCC99,FFFF99,CCFFCC,CCFFFF,99CCFF,CC99FF,FFFFFF';\n$custom_colours = 'e14d43,d83131,ed1c24,f99b1c,50b848,00a859,00aae7,282828';\n$init&#91;'theme_advanced_text_colors'] = $default_colours . ',' . $custom_colours;\nreturn $init;\n}\nadd_filter('tiny_mce_before_init', 'my_mce3_options');<\/code><\/pre>\n\n\n\n<div style=\"height:60px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><a name=\"custom_colors\"><\/a>Convert TinyMCE option for custom colour swatches to version 4<\/h2>\n\n\n\n<p>This solution will not work in WP 3.9, so we need to replace it with the working solution below (to be clear, the format of the colours array is changed, along with TinyMCE option name):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function my_mce4_options( $init ) {\n$default_colours = '\n\t\"000000\", \"Black\",\n\t\"993300\", \"Burnt orange\",\n\t\"333300\", \"Dark olive\",\n\t\"003300\", \"Dark green\",\n\t\"003366\", \"Dark azure\",\n\t\"000080\", \"Navy Blue\",\n\t\"333399\", \"Indigo\",\n\t\"333333\", \"Very dark gray\",\n\t\"800000\", \"Maroon\",\n\t\"FF6600\", \"Orange\",\n\t\"808000\", \"Olive\",\n\t\"008000\", \"Green\",\n\t\"008080\", \"Teal\",\n\t\"0000FF\", \"Blue\",\n\t\"666699\", \"Grayish blue\",\n\t\"808080\", \"Gray\",\n\t\"FF0000\", \"Red\",\n\t\"FF9900\", \"Amber\",\n\t\"99CC00\", \"Yellow green\",\n\t\"339966\", \"Sea green\",\n\t\"33CCCC\", \"Turquoise\",\n\t\"3366FF\", \"Royal blue\",\n\t\"800080\", \"Purple\",\n\t\"999999\", \"Medium gray\",\n\t\"FF00FF\", \"Magenta\",\n\t\"FFCC00\", \"Gold\",\n\t\"FFFF00\", \"Yellow\",\n\t\"00FF00\", \"Lime\",\n\t\"00FFFF\", \"Aqua\",\n\t\"00CCFF\", \"Sky blue\",\n\t\"993366\", \"Brown\",\n\t\"C0C0C0\", \"Silver\",\n\t\"FF99CC\", \"Pink\",\n\t\"FFCC99\", \"Peach\",\n\t\"FFFF99\", \"Light yellow\",\n\t\"CCFFCC\", \"Pale green\",\n\t\"CCFFFF\", \"Pale cyan\",\n\t\"99CCFF\", \"Light sky blue\",\n\t\"CC99FF\", \"Plum\",\n\t\"FFFFFF\", \"White\"\n\t';\n$custom_colours = '\n\t\"e14d43\", \"Color 1 Name\",\n\t\"d83131\", \"Color 2 Name\",\n\t\"ed1c24\", \"Color 3 Name\",\n\t\"f99b1c\", \"Color 4 Name\",\n\t\"50b848\", \"Color 5 Name\",\n\t\"00a859\", \"Color 6 Name\",\n\t\"00aae7\", \"Color 7 Name\",\n\t\"282828\", \"Color 8 Name\"\n\t';\n$init&#91;'textcolor_map'] = '&#91;'.$default_colours.','.$custom_colours.']';\n$init&#91;'textcolor_rows'] = 6; \/\/ expand colour grid to 6 rows\nreturn $init;\n}\nadd_filter('tiny_mce_before_init', 'my_mce4_options');\n<\/code><\/pre>\n\n\n\n<p>As you can see, the option is changed from <strong>theme_advanced_text_colors<\/strong> to\u00a0<strong>textcolor_map<\/strong>, and a simple array of HEX codes separated by commas now is changed to\u00a0a JavaScript array that\u00a0threat\u00a0elements as pairs of HEX colour value and colour nice name. All is wrapped in brackets.<\/p>\n\n\n\n<div style=\"height:60px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><a name=\"number_of_colors\"><\/a>Change\u00a0the number of colour swatches<\/h2>\n\n\n\n<p>Please note, that my default TinyMCE 4 has a limit of up to 40 colour swatches (80 array elements) distributed in a 5&#215;8 grid (ROWSxCOLS). So, to append custom colours after default colours, we need to increase the number of rows displayed on the swatches popup.<\/p>\n\n\n\n<p>To achieve this, we use&nbsp;<strong>textcolor_rows<\/strong> parameter.<\/p>\n\n\n\n<p>We even can change the grid layout and alter the default 5&#215;8 with, for example, 4&#215;10 by setting the parameters below:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$init&#91;'textcolor_rows'] = 5;\n$init&#91;'textcolor_cols'] = 10;<\/code><\/pre>\n\n\n\n<p>Please note, this is just an example. You can play with the layout and colour set as you wish.<\/p>\n\n\n\n<div style=\"height:60px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><a name=\"more_colors\"><\/a>How To Add &#8216;More Colors&#8217; Functionality?<\/h2>\n\n\n\n<p>TinyMCE 4\u00a0drops support for the  &#8216;More Colors&#8217; option, but now there is a WordPress plugin <a href=\"http:\/\/wordpress.org\/plugins\/tinymce-colorpicker\/\" target=\"_blank\" rel=\"noopener\">TinyMCE Color Picker<\/a> that brings back this functionality to WordPress 3.9+<\/p>\n\n\n\n<div style=\"height:60px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Reference<\/h2>\n\n\n\n<p><em>A <a title=\"Add custom text color WordPress 3.9 TinyMCE 4 Visual editor\" href=\"http:\/\/stackoverflow.com\/questions\/23171247\/add-custom-text-color-wordpress-3-9-tinymce-4-visual-editor\" target=\"_blank\" rel=\"noopener\">question posed to StakOverflow<\/a>&nbsp;encouraged me to explain how this problem can be resolved quickly and easily.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>TinyMCE 4 in WordPress 3.9 break old customization for adding custom colours, so here we have a tip about how to convert old code to new format supported in TinyMCE 4<\/p>\n","protected":false},"author":1,"featured_media":511,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[15,17,13,14,18,16,12],"class_list":["post-505","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tips","tag-3-9","tag-colours","tag-filters","tag-javascript","tag-more-colors","tag-tinymce","tag-tinymce-4"],"_links":{"self":[{"href":"https:\/\/urosevic.net\/wordpress\/wp-json\/wp\/v2\/posts\/505","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/urosevic.net\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/urosevic.net\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/urosevic.net\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/urosevic.net\/wordpress\/wp-json\/wp\/v2\/comments?post=505"}],"version-history":[{"count":7,"href":"https:\/\/urosevic.net\/wordpress\/wp-json\/wp\/v2\/posts\/505\/revisions"}],"predecessor-version":[{"id":3022,"href":"https:\/\/urosevic.net\/wordpress\/wp-json\/wp\/v2\/posts\/505\/revisions\/3022"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/urosevic.net\/wordpress\/wp-json\/wp\/v2\/media\/511"}],"wp:attachment":[{"href":"https:\/\/urosevic.net\/wordpress\/wp-json\/wp\/v2\/media?parent=505"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/urosevic.net\/wordpress\/wp-json\/wp\/v2\/categories?post=505"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/urosevic.net\/wordpress\/wp-json\/wp\/v2\/tags?post=505"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}