0

I 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 front 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 color picker 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...

2
  • Have you had a look at this: stackoverflow.com/questions/3326967/…
    – Joe
    Jun 23, 2013 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, 2013 at 22:13

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.