Is there any way to customize the Wordpress 3.8 color picker (on the custom field types) to use only colors i will define?
I need to have only 6 colors for a client, but they do not want to have all those colors, apart from 6 gradient colors.
Will be greatful for any help... I have been trying to do it for several days, but no positive solution:(
Thank you
Wordpress 3.5+ uses the Iris colorpicker which has several options available for use.
When initializing the object just assign the palettes option with an array of colors.
var colorOptions = {
// show a group of common colors beneath the square
// or, supply an array of colors to customize further
palettes: ['#4444,44','#ff2255','#559999','#99CCFF','#00c1e8','#F9DE0E','#111111','#EEEEDD']
};
jQuery('.my-color-picker-class').wpColorPicker(colorOptions);
If your using TinyMCE editor you can modify the color palette like so.
function my_mce4_options( $init ) {
$custom_colours = '
"e14d43", "Color 1 Name",
"d83131", "Color 2 Name",
"ed1c24", "Color 3 Name",
"f99b1c", "Color 4 Name",
"50b848", "Color 5 Name",
"00a859", "Color 6 Name"
';
$init['textcolor_map'] = '['.$custom_colours.']';
// Set number of color rows
$init['textcolor_rows'] = 3;
// Set number of color columns
$init['textcolor_cols'] = 2
return $init;
}
add_filter('tiny_mce_before_init', 'my_mce4_options');
We need to wp_enqueue_script the script and wp_enqueue_style the style with add_action to the functions.php file. Just include a jQuery file and stylesheet file by this script.
// Register Scripts & Styles in Admin panel
function custom_color_picker_scripts() {
wp_enqueue_style( 'wp-color-picker' );
wp_enqueue_script( 'iris', admin_url( 'js/iris.min.js' ), array( 'jquery-ui-draggable', 'jquery-ui-slider', 'jquery-touch-punch' ), false, 1 );
wp_enqueue_script( 'cp-active', plugins_url('/js/cp-active.js', __FILE__), array('jquery'), '', true );
}
add_action( 'admin_enqueue_scripts', custom_color_picker_scripts);
Now create a new javascript file as like cp-active.js and keep it avobe defined “/js/cp-active.js” file path using bellows code.
jQuery('.color-picker').iris({
// or in the data-default-color attribute on the input
defaultColor: true,
// a callback to fire whenever the color changes to a valid color
change: function(event, ui){},
// a callback to fire when the input is emptied or an invalid color
clear: function() {},
// hide the color picker controls on load
hide: true,
// show a group of common colors beneath the square
palettes: true
});
Add a textbox to your settings page with a CSS class for the color picker, where you want to dispaly the input text. I have use “color_code” for input $variable.
<input id="color_code" class="color-picker" name="color_code" type="text" value="" />
Please see more details on Add jQuery Color Picker WordPress Theme or Plugin
Here's a quick & dirty solution:
Go to wp-admin/js/iris.min.js
Search the palette colors there (about 1/3 from the beginning of the file). I found this:
_palettes:["#000","#fff","#d33","#d93","#ee2","#81d742","#1e73be","#8224e3"]
Replace these defaults with your own custom colors. I left black and white and then added our brand colors instead of #d33 and the rest.
Upload to server.
Works for now. But haven't tried yet if this survives the next Wordpress update.
Related
I have color settings as acf options page set as follows.
Color Settings:
Field Type : Repeater
Fields: color name and color value(e.g. orange => #FC7F34, blue => #14B1E7)
I am using this settings in my other custom fields as radio button.So when user choose button color it's saved as hex code(#FC7F34).
Now in front end I want both that color name and color value. I have tried below option but as we have multiple buttons I think this will effect the load time.
$data['colors'] = get_field( 'color_fields', 'option' );
foreach($data['colors'] as $color) {
$data[$color['color_value']] = $color['color_name'];
}
Result:
[#FC7F34] => Orange
[#14B1E7] => Blue
[#007DC5] => Dark Blue
Is there any other effective way to show Orange when we have #FC7F34 chosen as button color.
Any help/suggestions are welcome.
Yes it's possible using if else condition otherwise not possible because if you find on google orange code hex code then it showing different . now it's only possible from if condition .
if your color code is fix then one solution
if($data[$color['color_value']]=='#FC7F34') { echo 'orange';}
I'd like an option with the TinyMCE color picker to choose transparent as the color so a character (a "bullet") will still be there and take up space but will not be visible if it's color is transparent.
There's an "X" box option that says "No color" but this seems to make the color black, not transparent.
Does anyone know how to add a transparent color option to this color picker, or even make the "X" box implement transparent instead of black?
Thanks for any ideas.
I believe I was able to do that, I did some quick tests and it appears to be working fine.
I got the latest version of TinyMCE (4.1.10_dev) to access the textcolor plugin's non minified javascript there's this instruction:
if (value == 'transparent') {
resetColor();
} else {
selectColor(value);
}
What happens here? When you choose a color it runs the selectColor, which wraps the selected text in a span with the selected color. However, when you select the no color it removes this color span (that's why it goes back to black which is the default color) instead of setting it to transparent.
So if you do this:
//if (value == 'transparent') {
// resetColor();
//} else {
selectColor(value);
//}
Instead of removing the span it will change it to 'transparent' instead.
One important thing is that tinyMCE gets the plugin scripts automatically, so it only works with the minified versions, so after you do these changes you'll have to minify the script to the plugin.min.js and put it on the textcolro plugin's folder overwriting the one there.
I hope it helps.
The × button in the colorpicker removes any custom colours, it does not add a zero-opacity colour.
As you can see when looking at the source code or trying the full example there is no support for rgba() or opacity in the included colorpicker plugin. Only rgb() and hex unfortunately.
You may need to create your own small plugin to add the ability. There are a number of alternatives, for example:
Create a CSS class which you can add to elements in the editor. Then do your colour magic in your own CSS file.
Create a new button in the toolbar which makes the element transparent.
I would personally go with option two, something like this:
tinymce.init({
selector: 'textarea',
plugins: 'nocolour',
toolbar: 'nocolour',
external_plugins: {
"nocolour": "url_to_your/nocolour.js"
}
});
And nocolour.js:
tinymce.PluginManager.add('nocolour', function(editor, url) {
// Add a button that opens a window
editor.addButton('nocolour', {
text: 'Remove Colour',
icon: false,
onclick: function() {
editor.undoManager.transact(function() {
editor.focus();
// Here is where you add code to remove the colour
editor.nodeChanged();
});
}
});
});
Rafael's solution worked for me. I just wanted to document it a bit more and show what it looks like for TinyMCE 4.1.7.
When you click the "X" in the textcolor grid the "value" variable gets "transparent," rather than a hex value from the colorMap.
The relevant code in the textcolor plugin is:
value = e.target.getAttribute('data-mce-color'); // the hex color from the colorMap square that was clicked. "transparent" if X was clicked
if (value) {
if (this.lastId) {
document.getElementById(this.lastId).setAttribute('aria-selected', false);
}
e.target.setAttribute('aria-selected', true);
this.lastId = e.target.id;
// if (value == 'transparent') { // occurs if you select the "X" square
// removeFormat(buttonCtrl.settings.format);
// buttonCtrl.hidePanel();
// return;
// }
selectColor(value);
The five lines I've commented out remove formatting for the selected text, leaving it black, which doesn't seem useful. If you wanted the text black you could select the black square in the colorMap. Falling through to selectColor(value) with value = "transparent" sets transparent as the color.
Has anyone managed to create a button in TinyMCE 4 that will increment the font size of the selected text by, say, 1px?
The problem I'm having is getting ahold of the selected text, whether it's in a span already or not.
I'm willing to modify the TinyMCE source.
Thanks for any ideas.
You don't need to modify the source code, you can create a plugin.
Here is the documentation of how to create a plugin for TinyMCE:
http://www.tinymce.com/wiki.php/Tutorials:Creating_a_plugin
based on that you can create your own button (see working example)
here is part of the code:
var currentFontSize = new Number($(tinyMCE.activeEditor.selection.getNode()).css('font-size').replace('px','')); //remove the px part
currentFontSize = currentFontSize + 1; //increase font by one
tinymce.activeEditor.formatter.register('mycustomformat', {
inline : 'span',
styles : {'font-size' : currentFontSize + 'px'} //this is the font size incremented by one
});
tinymce.activeEditor.formatter.apply('mycustomformat'); //apply the format to the selected text
When the user marks a text, he can define a backgroundcolor with the colorpicker (textcolor.plugin).
Once saved he can change the background-color but not get rid of it.
background-color:white is no solution as the bodycolor can be RGB or even a picture.
How is the colorpicker to configure to remove the style-tag or at least insert a background-color:none?
Found a solution changing the plugin (textcolor). If there is a better way please be free to post it.
I added additional colors to the colorpicker. The Color #FFFFFe (near White) i marked as NO COLOR and changed the plugin as shown.
function onPanelClick(e) {
var buttonCtrl = this.parent(), value;
if ((value = e.target.getAttribute('data-mce-color'))) {
buttonCtrl.hidePanel();
value = '#' + value;
buttonCtrl.color(value);
if (value == '#FFFFFe') { //Changing the value to -1 causes deletion :-)
value = -1;
}
editor.execCommand(buttonCtrl.settings.selectcmd, false, value);
}
}
Researched a bit more since the given answer did not work in my version 4.5.0 of tinymce.
The textcolor plugin uses 'editor.formatter.remove(...)' to remove text color or background color upon selecting 'x' in the last option of the color palette for 'no color'.
While that function is used elsewhere successfully in tinymce (e.g. when removing italics from text), in the context of the textcolor plugin it does not remove color formatting.
Solution:
Replace the following in the textcolor's plugin.js:
editor.formatter.remove(format, {value: null}, null, true);
with:
editor.dom.removeAllAttribs(editor.selection.getNode());
...or in the minified version plugin.min.js:
a.formatter.remove(b,{value:null},null,!0),
with:
a.dom.removeAllAttribs(a.selection.getNode()),
...and things start working as intended.
I am using the Twenty Thirteen theme as a base for a custom child theme that I am creating. The client would like only three widgets in the footer and I need to evenly space them. When I put three widgets there is still room on the right for a fourth (I am not using the sidebar widget, which would knock the 4th widget below the top three).
I found this code in the functions.js file:
/**
* Arranges footer widgets vertically.
*/
if ( $.isFunction( $.fn.masonry ) ) {
var columnWidth = body.is( '.sidebar' ) ? 228 : 245;
$( '#secondary .widget-area' ).masonry( {
itemSelector: '.widget',
columnWidth: columnWidth,
gutterWidth: 20,
isRTL: body.is( '.rtl' )
} );
}
} )( jQuery );
It looks like it changes the width but how do I change it to make it only 3 widgets across instead of four?
Thanks,
Matt
The gutterWidth option adds additional spacing between columns, but not on the outer sides of the container. You can alter that value to increase spacing.
However, I think you are going to have to alter other files to properly achieve the task.