Divi Post Title Module: Open Featured Image in Lightbox

Written by Dan Mossop

I've previously written about how to add a lightbox effect to Divi featured images on plain Divi posts. In this post, we look at how to make the Divi Post Title module's featured image to do the same – open a larger version of the image when clicked.

Before

After

Open Divi Post Title Module Featured Image in a LIghtbox

Step 1: Add PHP Code

To make the Divi Post Title Module featured image open in a lightbox, first add the following PHP code to your site: 

add_action('wp_footer', 'dbc_open_featured_image_in_lightbox');
add_action('wp_enqueue_scripts', 'dbc_featured_image_in_lightbox_register_magnific_popup', 11); 

if (!function_exists('dbc_open_featured_image_in_lightbox')) {
	function dbc_open_featured_image_in_lightbox() {
		?>
		<script>
		jQuery(function($){
			$featured_img = $('.et_pb_post_title.featured-image-in-lightbox .et_pb_title_featured_container .et_pb_image_wrap img');
			$featured_img.wrap('<a class="et_pb_lightbox_image"></a>');
			$featured_img.each(function(){
				var img_url = $(this).attr('src');
                <?php if (apply_filters('dbc_open_featured_image_in_lightbox_use_fullsize_image', false)) { ?>
					img_url = img_url.replace(/-d+xd+(?=.(png|jpe?g|gif|bmp|webp))/i, '');
				<?php } ?>
				$(this).parent().attr('href', img_url);
			});
		});
		</script>
		<?php
	}
}
            
function dbc_featured_image_in_lightbox_register_magnific_popup() {
	if (!defined('ET_BUILDER_URI') || !defined('ET_CORE_VERSION') || version_compare(ET_CORE_VERSION, '4.10', '<')) { return; }
	wp_enqueue_style('dbc-featured-image-magnific-popup', ET_BUILDER_URI.'/feature/dynamic-assets/assets/css/magnific_popup.css', array(), ET_CORE_VERSION);
	wp_enqueue_script('dbc-featured-image-magnific-popup', ET_BUILDER_URI.'/feature/dynamic-assets/assets/js/magnific-popup.js', array( 'jquery' ), ET_CORE_VERSION, true);
}

Step 2: Add a class to the Divi Post Title module

Now, for any post title module you wish to apply the effect to, give it the "featured-image-in-lightbox" class, like so: 

Step 3: (Optional) Add a hover overlay

If you'd like to make it clearer to the user that they can click the featured image to open it in a popup, then you can add a hover overlay like this:

[dsm_before_after_image before_src="https://divibooster.com/wp-content/uploads/2023/10/image-29.png" after_src="https://divibooster.com/wp-content/uploads/2023/10/image-30.png" _builder_version="4.23" _module_preset="default" global_colors_info="{}" theme_builder_area="post_content"][/dsm_before_after_image]
You can do so by adding the following CSS code to your site:
/* === Add a hover icon to the post title module clickable featured images === */

:root {
  --post-title-module-featured-image-hover-brightness: 70%;
  --post-title-module-featured-image-hover-icon-color: white;
  --post-title-module-featured-image-hover-icon-font-size: 30pt;
}

/* Add a hover icon to the featured images in posts */
.et_pb_post_title.featured-image-in-lightbox .et_pb_title_featured_container .et_pb_image_wrap a.et_pb_lightbox_image:hover:before {
    content: "\55";
    font-family: ETmodules;
    color: var(--post-title-module-featured-image-hover-icon-color);
    font-size: var(--post-title-module-featured-image-hover-icon-font-size);
    text-shadow: 0px 0px 4px rgba(0, 0, 0, 1);
    position: absolute;
    top:50%; 
    left:50%;
    transform: translate(-50%, -50%);
    z-index: 1;
}
.et_pb_post_title.featured-image-in-lightbox .et_pb_title_featured_container .et_pb_image_wrap {
    position: relative;
}
/* Reduce the featured image brightness on hover */
.et_pb_post_title.featured-image-in-lightbox .et_pb_title_featured_container .et_pb_image_wrap a.et_pb_lightbox_image img:hover {
    filter: brightness(var(--post-title-module-featured-image-hover-brightness));
    transition: all 1s ease;
}
/* === End: Add a hover icon to the post title module clickable featured images === */

Run PHP Code Directly in your Divi Layouts

Unlock endless customization, automation, and dynamic functionality by seamlessly adding PHP code to your Divi pages and posts with the Divi PHP Code Module. Style, preview, and debug your PHP creations directly in the visual builder with robust error handling and enhanced security.

About Dan Mossop

Dan is a Scottish-born web developer, now living in Brisbane with his wife and son. He has been sharing tips and helping users with Divi since 2014. He created Divi Booster, the first Divi plugin, and continues to develop it along with 20+ other Divi plugins. Dan has a PhD in Computer Science, a background in web security and likes a lot of stuff, 

2 Comments

  1. Thanks for this Dan, great to have this functionality for the Post title module. Amazing!

    Reply
    • You're very welcome, Lee! I'm glad it helps :)

      Reply

Submit a Comment

Comments are manually moderated and approved at the time they are answered. A preview is shown while pending but may disappear if your are cookies cleared - don't worry though, the comment is still in the queue.

Your email address will not be published. Required fields are marked *.

We may earn a commission when you visit links on our website.

Latest From Divi Booster

How to Add the Post Status in Divi's Dynamic Content

Divi's Dynamic Content feature is great for enhancing your post/page templates with post-specific information. While Divi includes an option to show information such as the Post Created Date using Dynamic Content, there is no equivalent option for the Post Status....

Fix Divi Text Module "Regular" Font Weight Not Working

Are you encountering an issue where the font weights in Divi's Text Module don't seem to apply as expected? In particular, you might find that when you set the text module's body text font weight to "Regular", your font is actually assigned a weight of 500 instead of...

Make the Divi Gallery Module Swipeable

The Divi Gallery Module comes with a slider mode that lets you display images in a slider with clickable left/right arrows to scroll through the images. For mobile / touchscreen users, you can improve the user experience by allowing your user to swipe to navigate to...

How to Use Divi Dynamic Content in Woo Modules Product Selector

Divi's Dynamic Content is a powerful feature that lets you populate your Divi modules and theme builder templates with data pulled in various sources, such as custom fields. This allows for efficient organization and maintenance of your sites.Unfortunately, Divi's...

Random Divi Posts