I am trying to add color picker in wordpress settings API for plugin development. But I am facing problem to do that. I have code this for color picker.
// Create this function for color picker.
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 );
}
//Call it in my input field option
<tr valign="top">
<th scope="row"><label for="cursor_color">ScrollBar Color</label></th>
<td>
<input id= "cursor_color" type="text" name="ppmscrollbar_options[cursor_color]" value="<?php echo stripslashes($settings['cursor_color']);?>" class="my-color-field"/><p class="description">Select Icon holder color here. You can also add html HEX code.</p>
</td>
</tr>
//In my-script.js file I have written this bellow code.
jQuery(document).ready(function($){
$('.my-color-field').wpColorPicker();
});
I did not solve the issue. Can anyone tell me what can I do?
I’m really not sure why your code is not working, maybe the issue is not in the code you posted… The following is almost the same as yours, but a complete demonstration:
And
my-script.js
is exactly the same as yours.