✔ Provide theme default colors on color pickers
Completed by Rohan S.
- Assigned to
-
Rohan S.
- Due on
- Notes
-
It would be nice to help this client be consistent in their colour choices, while still giving them some flexibility.
It looks like ACF's API allows us to change the default choices in color pickers. For more info read here: https://www.advancedcustomfields.com/resources/adding-custom-javascript-fields/ and here (the last comment): https://support.advancedcustomfields.com/forums/topic/customise-color-picker-swatches/
The below should more or less work if you paste it into functions.php, but please give it a good look . You can find the theme colors at the top of _child_theme_variables_scss.
Rohan
function my_acf_input_admin_footer() { ?> <script type="text/javascript"> (function($) { acf.add_filter('color_picker_args', function( args, $field ){ // do something to args args.palettes = ['#5ee8bf', '#2f353e', '#f55e4f'] // return return args; }); })(jQuery); </script> <?php } add_action('acf/input/admin_footer', 'my_acf_input_admin_footer');
Comments & Events
The above code worked really well, thanks
Ian
Rohan Strydom completed this to-do.