Support

Account

Home Forums Front-end Issues Display color name with color picker Reply To: Display color name with color picker

  • Hi @mikealkeal

    The library you have linked is used for JS, so you need to get the name and apply it using JS too. Here’s an example how you can integrate PHP code and JS script:

    <script type="text/javascript">
    
      var n_match  = ntc.name("<?php the_field('color_field_name') ?>");
      n_rgb        = n_match[0]; // RGB value of closest match
      n_name       = n_match[1]; // Text string: Color name
      n_exactmatch = n_match[2]; // True if exact color match
    
      alert(n_match);
    
    </script>

    If you want to do it using PHP code, kindly check this thread: http://stackoverflow.com/questions/2993970/function-that-converts-hex-color-values-to-an-approximate-color-name.

    I hope this helps 🙂