Thanks, John, for your help. I appreciate it!
It turns out that having HTML code in the checkbox field itself is not a good idea. When using the field, the selections don’t stick (i.e. the selected options are gone the next time you edit the post).
So I went with only plain text values for the checkbox field and coded everything else in the template. Unfortunately, I read your code sample too late. Going with “switch” would have been a good idea, but as I’m not experienced with PHP, I handcrafted this subpar solution:
$tools_choices = get_field('tools'); if( $tools_choices ): ?> <h3 class="acf-title">Tools</h3> <?php foreach( $tools_choices as $name ): ?> <?php if( $name == 'Tool1' ): ?> <a href="https://url1.com/" target="_blank"><i class="fab fa-icon-x"></i><?php echo $name; ?></a> <?php elseif( $name == 'Tool2' ): ?> <a href="https://url2.com/" target="_blank"><i class="fab fa-icon-y"></i><?php echo $name; ?></a> <?php elseif( $name == 'Tool3' ): ?> <a href="https://url3.com/" target="_blank"><i class="fab fa-icon-z"></i><?php echo $name; ?></a> <?php else: ?> <p><i class="fab fa-icon-a"></i><?php echo $name; ?></p> <?php endif; ?> <?php endforeach; ?> <?php endif; ?>
It’s not the best code, but it works. If I later have the time and energy, I might change my code to a cleaner version based on your input.
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!
The ACF site is currently experiencing some issues.— Advanced Custom Fields (@wp_acf) September 21, 2022
We apologize for the inconvenience and we are working hard to get it back up and running as soon as possible.
© 2022 Advanced Custom Fields.