Home › Forums › Feature Requests › Customise Color Picker Swatches › Reply To: Customise Color Picker Swatches
I got stuck on this today, and all of these solutions seems a little overkill to me. I came up with this, which seems to be working fine for me. I’ve got mine pulling in the palettes from an options page, but the general idea should still be clear.
function acf_iris_palette(){
$palette = json_encode( array_column( get_field('palette', 'options'), 'colour' ) );
?>
<script type="text/javascript">
jQuery(function($){
var acfColourPicker = $('[data-type="color_picker"] input[type="text"]');
if ( acfColourPicker.length )
acfColourPicker.iris('option', 'palettes', <?php echo $palette; ?>);
});
</script>
<?php
}
add_action( 'admin_print_scripts', 'acf_iris_palette', 90 );
Hope that helps somebody 🙂
Edit: Apologies, I realise this doesn’t work on repeater fields or other dynamically generated fields. I’ll update this when I fix it.
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.