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 🙂
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.