Add an Alpha RGBa Color Picker to a WordPress Plugin Input Field

WordPress uses the Iris Color Picker as a tool which you can select a color for an input field in a plugin or theme or customizer, out of the box you can only add a hex color and not an Alpha RGBa color type that supports transparency.


No transparency here.

There are a couple of ways around this either as plugins or as extending the Iris color picker, there is a popular thread on this as an Open Issue on the Iris Github repo.

These 2 work for themes and plugins

And this one for the customizer

The one below is one that extends the Iris Color Picker and just works in input fields without calling other plugins – as the author extends the existing wp-color-picker with his wp-color-picker-alpha code.

So for plugin usage in an input field you’ll need to complete the following.

Enqueuing the Color Scripts

Get the Github repo and extract wp-color-picker-alpha.min.js from the dist directory, this needs to be enqueued at your plugins settings page as well as the regular wp-color-picker script.

The wp-color-picker-alpha.min.js is dependent owp-color-picker.

function my_plugin_admin_scripts($hook) {
if ( 'settings_page_myplugin' != $hook ) { //set your plugin page
wp_enqueue_style( 'wp-color-picker' );
wp_enqueue_script( 'wp-color-picker-alpha', plugins_url( '/js/wp-color-picker-alpha.min.js', __FILE__ ), array( 'wp-color-picker' ), '1.0.0', true );
add_action( 'admin_enqueue_scripts', 'my_plugin_admin_scripts' );
view raw rgba.php hosted with ❤ by GitHub

Adding the Alpha Attribute to the Input Field

So now with that in place any input fields that you need to apply the rgba color format to, you need to add in a data attribute to the input field of  data-alpha=true as well as the  class=color-picker attribute. Example below…

function my_overlay_callback() {
$options = get_option( 'plugin_settings' );
if( !isset( $options['my_overlay'] ) ) $options['my_overlay'] = 'rgba(0,0,0,0.85)';
echo '<input type="text" class="color-picker" data-alpha="true" data-default-color="rgba(0,0,0,0.85)" name="plugin_settings[my_overlay]" value="' . sanitize_text_field($options['my_overlay']) . '"/>';
view raw input_field.php hosted with ❤ by GitHub

Also you can set a default color by adding the attribute data-default-color=rgba(0,0,0,0.85)“.

That’s it nice and easy – giving you …


This allows both regular hex color and RGBa with the outer right slider adjusting the transparent value.




  1. Pablo on September 6, 2018 at 10:23 pm

    Just to let anybody know. I had a problem. Script didn’t work. The line “wp_enqueue_script( ‘wp-color-picker-alpha’, plugins_url( ‘/js/wp-color-picker-alpha.min.js’, __FILE__ ), array( ‘wp-color-picker’ ), ‘1.0.0’, true );” ends with “true” value indicating that the script should be placed in the footer. (I suppose) When I removed it my script started to work. I believe there is no footer in my plugin admin page.

    I also suppose that 1.0.0 should be changed to the latest script version. This is now 2.1.3


  2. Michael on January 12, 2018 at 11:10 am

    Is there any update to this, trying to implement it within a genesis site, I am not wishing it to be a plugin as it will be theme specific, I got to work once but could not get it to replace the old picker, it just loaded itself under neath ????

    • Neil Gowran on February 3, 2018 at 10:29 pm

      The latest version of the script fixes this issue

Leave a Comment