Help Center
How to Set Icon Color Dynamically in Maps Listing

How to Set Icon Color Dynamically in Maps Listing

This tutorial explains how to dynamically change map marker icon colors in JetEngine Map Listings based on post meta field values using a macro or shortcode in Elementor, Gutenberg, and Bricks editors for WordPress.

Before you start, check the tutorial requirements:

  • Elementor (Free version), Block editor (Gutenberg), or Bricks

  • JetEngine plugin installed and activated with the Map Listing set

    If you haven't done it yet, proceed to this tutorial

Displaying dynamic, visually informative maps can significantly enhance the user experience, especially when map markers adapt based on your content. 

With JetEngine’s Map Listing widget/block/element, you can customize marker icon colors dynamically, assigning a different color to each post, term, CCT item, user, etc. via the custom fields.

Things to know

For this tutorial, we use the Travengo dynamic template.

Backend Preparation

Create a “Colorpicker” meta field

In our case, we display posts on the map from the “Tours” Custom Post Type, so we need to add a meta field for the icon color into the CPT source.

We open the WordPress Dashboard > JetEngine > Post Types tab and click to edit the “Tours” CPT. Here, we scroll the page down to the Meta Fields section and hit the “New Meta Field” button.

Fill in the Label and Name/ID and select the “Colorpicker” or “TextField type. Set other meta field settings if needed and save the changes.

colorpicker meta field

Then, we edit the custom posts and fill in the meta fields.

Things to know

A color is considered valid only if it is specified in HEX, RGB, or HSL format. Color names like "red," "green," or "goldenrod" are not accepted as valid inputs.

filling in colorpicker field for posts

Generate a shortcode/macro

To apply dynamic icon colors to the Map Listing, you need to generate a shortcode or macro.

Proceed to the WordPress Dashboard > JetEngine > JetEngine > Shortcode Generator to generate a shortcode.

Select “JetEngine Data” in the Shortcode dropdown, “Meta Data” as Source, and the required Meta Field. Adjust other settings if needed and copy the shortcode from the bar at the bottom of the page ( in our case).

shortcode with jetengine meta data from the colorpicker

If you want to create a macro, open the Macros Generator tab.

Choose “Current meta value” in the Macros dropdown and enter the “Colopicker” meta field name into the Meta field. After that, you can copy the macro (%current_meta|icon_color% as an example).

current meta value macro for the colorpicker meta field

Dynamic Icon Color in Elementor

Open a page with the Elementor editor that contains the Map Listing widget.

In the General settings tab, ensure that the Listing and Address Meta Field are configured.

map listing general settings in elementor

Then, unroll the Marker tab and select any Marker Type (e.g., we pick “Icon” and set the “Map marker alt” Icon from the Icon Library). For our case, we also disabled the Marker Clustering toggle.

map listing marker settings in elementor

Now, you can open the Style section and modify the marker appearance in the Marker style tab. That’s how the marker will look on the map if the post meta field has no value.

map listing marker style settings in elementor

To apply dynamic colors, go back to the Marker settings tab of the Content section, enable the Use different markers by conditions toggle, and press the “+ Add Item” button.

In the Item repeater, select the “Icon” Marker Type.

If needed, set the Icon and pick an option from the Apply Icon Color to dropdown:

  • Fill — fills the icon with the adjusted color;
  • Stroke — applies the adjusted color to the outline (stroke) of the icon only;
  • Both — applies the adjusted color to both the fill and the stroke of the icon;
  • Keep SVG colors — retains the original colors defined in the SVG file, ignoring any adjusted color settings.

Into the Dynamic Icon Color bar, enter the macro or shortcode generated previously.

Things to know

The Dynamic Icon Color option takes over the Icon Color, so you need to set either one or the other for each item.

In the Apply this marker if dropdown, select the “Dynamic color not empty” variant.

After that, markers on the map will change their color according to the post meta field values. Changes can be saved by pushing the “Publish” button.

icon color depends on the post meta field value

Dynamic Icon Color in Gutenberg

Open a page with the WordPress Block editor where the Map Listing block is placed.

In the General settings tab, ensure that the LISTING and ADDRESS META FIELD are configured.

map listing general settings in gutenberg

Then, unroll the Marker tab and select any MARKER TYPE (e.g., we pick “Image/Icon” and set the Image/Icon from the Media Library). For our case, we also disabled the Marker Clustering toggle.

map listing marker settings in gutenberg

If the JetStyleManager free plugin is installed and activated, the “paintbrush” icon appears in the upper right corner. By clicking on it, you’ll open the Map Listing style settings. In the Marker tab, you can customise how the marker will look on the map if the post meta field has no value.

map listing marker style settings in gutenberg

To apply dynamic colors, go back to the Marker settings tab of the Block section, enable the Use different markers by conditions toggle, and press the “+ Add new item” button.

If needed, set the Image/Icon pick an option from the APPLY ICON COLOR TO dropdown:

  • Fill — fills the icon with the adjusted color;
  • Stroke — applies the adjusted color to the outline (stroke) of the icon only;
  • Both — applies the adjusted color to both the fill and the stroke of the icon;
  • Keep SVG colors — retains the original colors defined in the SVG file, ignoring any adjusted color settings.

Into the DYNAMIC ICON COLOR bar, enter the macro or shortcode generated previously.

Things to know

The DYNAMIC ICON COLOR option takes over the color picker above, so you need to set either one or the other for each item.

In the APPLY THIS MARKER IF dropdown, select the “Dynamic color not empty” variant.

Finally, you can save the settings by clicking the “Save” button.

dynamic icon color option in the wordpress block editor

After that, on the front end, markers on the map will change their color according to the post meta field values.

icon color depends on the post meta field value on the front end

Dynamic Icon Color in Bricks

Open a page with the Bricks editor where the Map Listing element is placed.

In the GENERAL settings tab, ensure that the Listing and Address Meta Field are configured.

map listing general settings in bricks

Then, unroll the MARKER tab and select any Marker Type (e.g., we keep the default “Icon” option). Also, we disabled the Marker clustering toggle for now.

map listing marker settings in bricks

Now, you can open the STYLE section and modify the marker appearance in the MARKER style tab. That’s how the marker will look on the map if the post meta field has no value.

map listing marker style settings in bricks

To apply dynamic colors, go back to the MARKER settings tab of the CONTENT section, enable the Use different markers by conditions toggle, and press the “+ ADD MARKER” button.

In the Repeater item, select the “Icon” Marker Type and set the Icon if needed.

Into the Dynamic Icon Color bar, enter the macro or shortcode generated previously. 

!Things to know

The Dynamic Icon Color option takes over the Icon color, so you need to set either one or the other for each item.

In the Apply this marker if dropdown, select the “Dynamic color not empty” variant.

After that, markers on the map will change their color according to the post meta field values. Finally, you can save the settings by clicking the “Save” button.

dynamic icon color option in bricks

That’s all. Now you know how to dynamically change map marker icon colors in JetEngine Map Listings based on post meta field values using a macro or shortcode in Elementor, Gutenberg, and Bricks editors for WordPress.

Was this article helpful?
YesNo

Need help?

Ask Facebook community

Get answers from 30K+ Crocoblock Community experts from all over the world.

Start a live chat

Ask question to support agent and share its details via chat messages.