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've just released ACF 5.12.3 with a security fix to prevent arbitrary file uploads to forms with ACF fields.
— Advanced Custom Fields (@wp_acf) July 14, 2022
Now that we've released this update, we recommend updating your sites as soon as possible.
© 2022 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.