Support

Account

Home Forums Backend Issues (wp-admin) Add the hex value as background color in a custom column Reply To: Add the hex value as background color in a custom column

  • I play a lot with the code and I feel that I had the results that I want.

    add_action( 'manage_pages_custom_column' , 'background_add_custom_column_data', 10, 2 );
    add_action( 'manage_posts_custom_column' , 'background_add_custom_column_data', 10, 2 );
    function background_add_custom_column_data( $column, $post_id ) {
        switch ( $column ) {
            case 'colors' :
               if( have_rows('colors') ):
                while ( have_rows('colors') ) : the_row(); ?>
            <div style="background-color:<?php the_sub_field('hex_color');?>;">
            <div style="width:80px;height:80px;"></div>
    <?php
        endwhile;
        endif;
        break;
        }

    }