Home › Forums › General Issues › Color Picker Palette(s) more than one › Reply To: Color Picker Palette(s) more than one
For anyone where $field.data('key')
is invalid, the following code worked for me.
The main difference is that you’re targeting $field[0]['dataset']['key']
.
<?php
// Set the default color palette for certain fields
function set_acf_color_picker_default_palettes() {
?>
<script>
let setDefaultPalette = function() {
acf.add_filter('color_picker_args', function( args, $field ){
// Find the field key
let targetFieldKey = $field[0]['dataset']['key'];
// Set color options for the field
// if field is accordion_icon_background_color
if ( 'field_60d621b2f0e04' === targetFieldKey ) {
args.palettes = [ '#999', '#ae241a', '#004990' ];
}
// Return
return args;
});
}
setDefaultPalette();
</script>
<?php
}
add_action('acf/input/admin_footer', 'set_acf_color_picker_default_palettes');
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.