28th Jun '24
/
2 comments

ACF Checkbox Items with Custom SVG Bullets in Bricks

This tutorial walks you through outputting the choice values of a ACF Checkbox field with a SVG icon to the left of the list items.

Field group:

Field being populated when a Page is being edited:

Frontend after implementing the tutorial:

Step 1

Create a field group having a Checkbox-type of custom field using ACF.

Edit your posts (or Pages or CPT items) and select choices for each.

Step 2

Edit your singular template for your post type or a specific Page with Bricks.

Add a Code element and paste:

<?php

$choices = get_field( 'room_amenities' );

if ( $choices ): ?>

  <ul>
      <?php foreach( $choices as $choice ): ?>
          <li><?php echo $choice; ?></li>
      <?php endforeach; ?>
  </ul>

<?php endif; ?>

Replace room_amenities with your field name.

Click the Sign code button.

Step 3

Click STYLE → CSS and paste:

%root% ul {
	list-style-type: none;
	margin: 0;
	padding: 0;
}

%root% li {
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' height='24px' viewBox='0 0 24 24' width='24px' fill='%235f6368'%3E%3Cpath d='M0 0h24v24H0V0zm0 0h24v24H0V0z' fill='none'/%3E%3Cpath d='M16.59 7.58L10 14.17l-3.59-3.58L5 12l5 5 8-8zM12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8z'/%3E%3C/svg%3E");
	background-repeat: no-repeat;
	background-position: left 2px;
	padding-left: 30px;
	margin-bottom: 20px;
}

%root% li:last-child {
	margin-bottom: 0;
}

If you would like to show a different icon, open the icon SVG file in a text editor, copy its HTML and paste it under Insert SVG here.

Then copy the generated CSS property code from Ready for CSS and replace the one in the above with it.

Reference

https://www.advancedcustomfields.com/resources/checkbox/#display-values-in-a-list

Get access to all 611 Bricks code tutorials with BricksLabs Pro

2 comments

  • Fantastic, Thanks for sharing

    What would you do differently to this code for a different icon for each checkbox ?

    For example, Wifi showing a Wifi icon, Iron showing an Iron icon

    • A

      A Repeater field with icon/image sub field and a text sub field. Then set up a Bricks query loop of your Repeater type and map the fields to Bricks elements.

Leave your comment

 

Related Tutorials..

Pro
Category Grid with ACF Images in Bricks

Category Grid with ACF Images in Bricks

Creating a grid of post categories, each category card showing an image from an ACF field, category name & description.
Categories:
How to populate a map with dynamic markers from a CPT using ACF in Bricks (PART 1)

How to populate a map with dynamic markers from a CPT using ACF in Bricks (PART 1)

This tutorial provides the PHP & JS codes that can be pasted in order to create a dynamic map with markers populated from a custom…
Categories:
Pro
ACF Checkbox Sub Field as Unordered List in Bricks

ACF Checkbox Sub Field as Unordered List in Bricks

Updated on 22 Sep 2023 This Pro tutorial shows how the checked options of a Checkbox-type of Sub Field inside a ACF Repeater field can…
Categories:
Pro
Merging ACF Gallery Images with Featured Image in Bricks

Merging ACF Gallery Images with Featured Image in Bricks

Updated on 12 Mar 2025 In the Bricks Facebook group a user asks: Merging images from different fields into a single gallery Hi, I have…
Categories:
Pro
Conditional Rendering of ACF Repeater Rows Based on True / False Sub Field in Bricks

Conditional Rendering of ACF Repeater Rows Based on True / False Sub Field in Bricks

This Pro tutorial provides the steps to modify a ACF Repeater query loop to only output the rows for which a True / False type…
Categories:
Pro
Custom Dynamic Data Tags for ACF Field Label, Prefix and Suffix in Bricks

Custom Dynamic Data Tags for ACF Field Label, Prefix and Suffix in Bricks

Bricks lacks built-in dynamic tags for ACF field labels, prefixes, and suffixes. This tutorial shows how to add them using custom dynamic tags.
Categories: