Last active
April 1, 2025 01:05
-
-
Save benpearson/39039f1bcfe16892aee7b7aef3f6cc5b to your computer and use it in GitHub Desktop.
WordPress: Enqueue filter for ACF colour picker
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
// ACF colour picker palette | |
acf.add_filter('color_picker_args', function( args, $field ){ | |
args.palettes = ['#000000', '#FFFFFF', '#FC4D00', '#6750AA', '#F2E9DB', '#DCD3E7'] | |
return args; | |
}); |
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 dt_acf_admin_footer() { | |
?> | |
<script type="text/javascript"> | |
(function($) { | |
acf.add_filter('color_picker_args', function(args, $field) { | |
args.palettes = ['#000000', '#FFFFFF', '#FC4D00', '#6750AA', '#F2E9DB', '#DCD3E7']; | |
return args; | |
}); | |
})(jQuery); | |
</script> | |
<?php | |
} | |
add_action('acf/input/admin_footer', 'dt_acf_admin_footer'); |
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
/** | |
* Add script to set palette in ACF color picker fields. | |
*/ | |
function dt_acf_admin_enqueue_scripts() | |
{ | |
wp_enqueue_script( | |
'dt-admin-acf-colour', | |
get_template_directory_uri() . '/dt-js/acf-color-picker-palette.js', | |
[], | |
filemtime(get_template_directory() . '/dt-js/acf-color-picker-palette.js'), | |
true | |
); | |
} | |
// add_action('acf/input/admin_enqueue_scripts', 'dt_acf_admin_enqueue_scripts'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment