Support

Account

Home Forums Feature Requests Customise Color Picker Swatches Reply To: Customise Color Picker Swatches

  • I’m trying this with version 5, and I had to adjust this a little — to change the jQuery selector from ‘.color_picker’ to ‘.acf-color_picker’. Here’s my code:

    function load_javascript_on_admin_edit_post_page() {
    	global $parent_file;
    
      // If we're on the edit post page.
    	if (
    	  strpos($parent_file, 'post-new.php') !== -1 ||
    	  strpos($parent_file, 'edit.php') !== -1 ||
    	  strpos($parent_file, 'post.php') !== -1
    	) {
    		echo "
    		  <script>
    		  jQuery(document).ready(function(){
    			jQuery('.acf-color_picker').iris({
    			  palettes: ['#e40571', '#4b63a4', '#ffcb05', '#fff', '#000'],
    			  change: function(event, ui){
    				jQuery(this).parents('.wp-picker-container').find('.wp-color-result').css('background-color', ui.color.toString());
    			  }
    			});
    		  });
    		  </script>
    		";
    	}
    }
    add_action('in_admin_footer', 'load_javascript_on_admin_edit_post_page');