Limited Time Sale - 10% Discount! Use Code:U5ZBQTEY

Custom Click Actions

This document explains how to use the custom click action filter available in the Divi Dynamic Gallery plugin.

Divi Dynamic Gallery has 5 available click actions which can be set in the module’s Content tab -> Elements Section -> Overlay Click Action option (Show Overlay toggle must be turned on):

  • None
  • Lightbox
  • Lightbox gallery
  • Open Media URL
  • Open Custom Link

Setting the click action in the module’s settings will assign that click action to every item in the grid.

The custom click action filter below will override the global click action detailed above, allowing you to set the click action on a per image basis. In other words, each image can have it’s own click action.

The following code is an example of how the custom click action filter can be applied to each image. You would add this code to your child theme’s functions.php file:

In the example above, we are checking the value of the “ddg_click_action” custom field. This custom field would get added to each image you wanted to create a custom click action for.

*Custom fields are not natively available for media attachments so you’ll need to add them using a plugin like ACF or using custom code.

Next, we are returning a different value to the filter depending on the value of the custom field. Since the custom field values are the same as the click action values, it would make more sense to simply check if the field exists and return its value if it did. For this tutorial I am displaying the values to make it easier to see how the filter works.

These are the corresponding return values needed for each click action:

  • None – none
  • Lightbox – lightbox
  • Lightbox gallery – gallery
  • Open Media URL – url
  • Open Custom Link – link

Notice in the example code above if the “ddg_click_action” custom field is empty, we revert back to the $default_action. This is the action set in the module’s Overlay Click Action option mentioned earlier. Using the $default_action, you can see how you could set a click action for all images in the gallery in the module’s settings and only change the click action for certain images.

The example above uses the value of a custom field, but you could apply any logic to the filter. For example you could apply different click actions to images based on image title, description, caption, alt tag, custom taxonomy term, etc.

Pin It on Pinterest

Share This