Customising Wordpress Color Picker

后端 未结 4 1027
执笔经年
执笔经年 2021-02-06 14:38

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, bu

4条回答
  •  滥情空心
    2021-02-06 15:19

    yes,

    Wordpress uses the Iris colorpicker , and if you will go to it´s page you will see all the methods and options ..

    Basically , you add this :

     palettes: ['#e5003d','#A6FF4C','#757584','#99CCFF','#00c1e8','#111111','#ECECFB']
    

    to your option when initializing the object ..

        jQuery('#my-ID .my-color-picker-class').each(function(){
            jQuery(this).wpColorPicker({
                // 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){},
                // a callback to fire when the input is emptied or an invalid color
                clear: function() {},
                // hide the color picker controls on load
                hide: true,
                // set  total width
                width : 200,
                // show a group of common colors beneath the square
                // or, supply an array of colors to customize further
                palettes: ['#444444','#ff2255','#559999','#99CCFF','#00c1e8','#F9DE0E','#111111','#EEEEDD']
            });
    

    All this of course if you code your own custom field..

    If you use some plugin or such - It will depend on that plugin mechanism ..

提交回复
热议问题