Support

Account

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.