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;
}
}
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.