Created
March 1, 2025 10:01
-
-
Save Kristjan-Reinsberg/5a5b369c8aa5cab309896278e57cbc5a to your computer and use it in GitHub Desktop.
WP ACF colorpicker has theme colors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function adm_enqueue_custom_acf_color_picker_script() { | |
| //wp_enqueue_script('jquery'); // ACF filters requirement. If not working | |
| $eas_theme__colors = [ | |
| '#003cff', //light blue | |
| '#0000b4', //darker blue | |
| '#3c0078', //purple | |
| '#1d4432', //green | |
| '#fcedc5', //yellow | |
| '#f0f1f2', //gray | |
| '#ffffff', //white | |
| ]; | |
| // Modify the ACF color picker | |
| wp_add_inline_script('acf-input', ' | |
| (function($) { | |
| acf.add_filter("color_picker_args", function( args, $field ){ console.log($field); | |
| args.palettes = '. json_encode($eas_theme__colors) . ' | |
| return args; | |
| }); | |
| })(jQuery); | |
| '); | |
| } | |
| add_action('acf/input/admin_enqueue_scripts', 'adm_enqueue_custom_acf_color_picker_script'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment