0

vI am struggling with this problem: i'm currently trying to implement a color picker for my theme admin page (specifically, i am using this one: http://bgrins.github.io/spectrum/ ).

Loading the color picker in the frontend is very easy: i'm just referencing the js file:

<script type="text/javascript" src="wp-content/themes/mytheme/js/spectrum.js"></script>

pasting the script:

<script>
    $(".basic").spectrum({
    color: "#f00",
    change: function(color) {
    $("#basic-log").text("change called: " + color.toHexString());
    }
});
</script>

and then, obviously, adding the colorpicker field where i need it:

<input type='text' class="basic"/>

It's working perfectly. However, if i try to do the same in my functions.php file, to have it displayed in my backend, it doesn't work at all.


Ps. Before trying out this color picker, i tried to use the Wordpress Iris (the default one included in every wp installation), by following this tutorial (http://make.wordpress.org/core/2012/11/30/new-color-picker-in-wp-3-5/ ), to no avail.

I also installed a plugin that supposedly was a demo showing how to implement the default color picker ( https://github.com/rachelbaker/iris-color-picker-demo ). It didn't work either.

Any help would be immensely appreciated, i feel like i'm missing something but i can't understand what...

  • Have you had a look at this: http://stackoverflow.com/questions/3326967/how-to-add-custom-javascript-to-wordpress-admin – Joe Jun 23 '13 at 22:11
  • it should just be `wp_enqueue_script('whatever', 'path/to/my/script.js');` in functions.php. No need for `is_admin()` because you want it accessible on the front and on the backend. Then, you'll have another file calling it, and you'll need to do `(function($){ // code })(jQuery);` when working in the WP backend. – Ohgodwhy Jun 23 '13 at 22:13

0 Answers0