Home Forums Front-end Issues Display color name with color picker


Display color name with color picker

  • Hello,
    i’m using color picker in a repetear field and I want to display to my users the “name of color” for each color in frontend.
    I find a JS for the name :

    can you help me ?

    thank you.

  • 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  ="<?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

    If you want to do it using PHP code, kindly check this thread:

    I hope this helps πŸ™‚

  • hi
    Thank you !

    I’ll try this πŸ™‚

  • I share my code for those who want


     <?php if( have_rows('field_name_repeater') ): ?>
    <?php while( have_rows('field_name_repeater') ): the_row(); 
    $color = get_sub_field('fied_colorpicker');
    <div class="color-repeat" data-color="<?php  echo $color; ?>">
    <div class="colorName"></div>
    <?php endwhile; ?>
    <?php endif; ?>

    JS :

    $('.color-repeat').each(function( ) {
    	var color = $(this).data( "color" );
    	var n_match  =;
    	n_name       = n_match[1]; // Text string: Color name
Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.