i tried to use iris color picker in my plugin admin area but when i implemented i’m getting this error-
TypeError: $(…).wpColorPicker is not a functionCode-
function sam()
{
wp_enqueue_style( 'wp-color-picker');
wp_enqueue_script( 'wp-color-picker');
}
add_action( 'admin_enqueue_scripts', 'sam' );
<!--HTML-->
<input type="text" value="#bada55" class="ir" />
<!--SCRIPT-->
<script type="text/javascript">
jQuery(document).ready(function($){
$('.ir').wpColorPicker();
});
</script>
Why am I getting this error any clue? where am I making wrong?
This is happening because you are calling wpColorPicker function before loading wp-color-picker script so to overcome this situation call wpColorPicker() function after loading wp-color-picker script by adding following script in js file in this example i have added it in wp-color-picker-script.js.
and then enqueue it using admin_enqueue_scripts action after enqueuing wp-color-picker script and add wp-color-picker as a dependency for it as shown in the following code.
Try with changing your code like this..hope it will work
In your template
In your js file (wp-color-picker-script.js)
Another possible reason for this is a rogue filter on
script_loader_tag
, this was what was happening for me.In this case, the script was enqueued properly, but this filter was removing the script tag completely, so it was not being loaded at all, then giving the wpColorPicker is not a function console error.
Just in case anyone has the same problem. 😉
I have this in my functions.php of an child theme.
Just call wp-color-picker script without creating a function:
This error is showing because you have
script_debug
is set on . turn it off .I know its not a good solution but i m unable to find the other way around. Looks like bug in wp core.