Skip to content

Instantly share code, notes, and snippets.

@westcoastdigital
Created November 8, 2021 01:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save westcoastdigital/576da079d0bd2d0b63062ac877814d11 to your computer and use it in GitHub Desktop.
Save westcoastdigital/576da079d0bd2d0b63062ac877814d11 to your computer and use it in GitHub Desktop.
ACF Radio as Image Select
/**
* Create a radio button field and set it to horizontal
* Add each choice with image as label like beow
* animation : <img src="/wp-content/themes/cobaltdesign/img/animation.svg" />
* Change $field_name in the acf_icon_css function to what you called your theme
*/
function acf_icon_css()
{
$field_name = 'expertise_icon';
$css = '<style>
div[data-name="' .$field_name . '"] ul.acf-radio-list,
tr[data-name="' .$field_name . '"] ul.acf-radio-list {
background: white;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: justify;
-ms-flex-pack: justify;
justify-content: space-between;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
}
div[data-name="' .$field_name . '"] ul.acf-radio-list label input,
tr[data-name="' .$field_name . '"] ul.acf-radio-list label input {
display: none;
}
div[data-name="' .$field_name . '"] ul.acf-radio-list li,
tr[data-name="' .$field_name . '"] ul.acf-radio-list li {
height: 80px;
}
div[data-name="' .$field_name . '"] ul.acf-radio-list label img,
tr[data-name="' .$field_name . '"] ul.acf-radio-list label img {
height: 60px;
margin: 10px 0;
border: 1px solid white;
border-radius: 10%;
}
div[data-name="' .$field_name . '"] ul.acf-radio-list label img:hover,
tr[data-name="' .$field_name . '"] ul.acf-radio-list label img:hover {
border-color: #2271b1;
}
div[data-name="' .$field_name . '"] ul.acf-radio-list label.selected img,
tr[data-name="' .$field_name . '"] ul.acf-radio-list label.selected img {
border-color: #2271b1;
}
</style>';
echo $css;
}
add_action('admin_head', 'acf_icon_css');
@westcoastdigital
Copy link
Author

Screen Shot 2021-11-08 at 9 35 34 am

Screen Shot 2021-11-08 at 9 36 04 am

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment