4

I'm having difficulty implementing the color picker exactly the same as WordPress in my plugin.

Is there any official wordpress documentation on how to use this feature?

6

Yes, there is: https://make.wordpress.org/core/2012/11/30/new-color-picker-in-wp-3-5/

1. You should enqueue scripts and styles...

add_action( 'admin_enqueue_scripts', 'mw_enqueue_color_picker' );
function mw_enqueue_color_picker( $hook_suffix ) {
    // first check that $hook_suffix is appropriate for your admin page
    wp_enqueue_style( 'wp-color-picker' );
    wp_enqueue_script( 'my-script-handle', plugins_url('my-script.js', __FILE__ ), array( 'wp-color-picker' ), false, true );
}

2. ... add an input...

<input type="text" value="#bada55" class="my-color-field" data-default-color="#effeff" />

3. ... and call wpColorPicker function

jQuery(document).ready(function($){
    $('.my-color-field').wpColorPicker();
});
  • You enqueue scripts and styles incorrectly, so they're not loading at all. Why? Because you provide incorrect url to these files. As a path you use plugins_url( 'personalize-wp-login/js/bootstrap.min.js' ) and it doubles personalize-wp-login part. Take a look at this answer: wordpress.stackexchange.com/a/216881/34172 – Krzysiek Dróżdż May 23 '18 at 20:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.