admin管理员组文章数量:1410712
Trying to get both the hex and RGB value of a color from the native color picker in Wordpress, user chooses the color via a custom metabox in the admin. Just need to save both values as meta for re-use in the interface.
jQuery(function() {
jQuery('.color-field').wpColorPicker();
});
Any feedback would be greatly appreciated. TXS.
Trying to get both the hex and RGB value of a color from the native color picker in Wordpress, user chooses the color via a custom metabox in the admin. Just need to save both values as meta for re-use in the interface.
jQuery(function() {
jQuery('.color-field').wpColorPicker();
});
Any feedback would be greatly appreciated. TXS.
Share Improve this question asked Oct 18, 2019 at 16:57 SimonSimon 4273 silver badges9 bronze badges 1 |1 Answer
Reset to default 1Thanks for your help Sally, here is the completed jQuery which pushes the RGB value to another field. Name of the RGB field has _rgb
at the end.
jQuery(function() {
var myOptions = {
// you can declare a default color here,
// or in the data-default-color attribute on the input
defaultColor: false,
// a callback to fire whenever the color changes to a valid color
change: function(event, ui){
var rgb = ui.color.toCSS( 'rgb' );
var name = jQuery(this).attr("name");
name = '#' + name + '_rgb';
jQuery(name).val(rgb);
},
// 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
// or, supply an array of colors to customize further
palettes: true
};
jQuery('.color-field-custom').wpColorPicker(myOptions);
});
And here is what the custom field looks like below the color picker field.
<input type="text" name="destination_secondary_color_rgb" id="destination_secondary_color_rgb" value="<?php echo get_post_meta($post->ID, 'destination_secondary_color_rgb', true); ?>" />
本文标签: custom fieldWordpress colorpicker save both hex and RGB
版权声明:本文标题:custom field - Wordpress colorpicker save both hex and RGB 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745066464a2640549.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
change
event:change: function ( event, ui ) { var rgb = ui.color.toCSS( 'rgb' ); ... }
- see the "Advanced usage" section here and the Color.js docs. – Sally CJ Commented Oct 18, 2019 at 18:06