Skip to content

Instantly share code, notes, and snippets.

@EldarAgalarov
EldarAgalarov / divi-lightbox-for-regular-images.php
Last active July 11, 2018 05:40
Wraps regular post images with Divi Lightbox
/* Add this into functions.php of child theme */
/* Wrap post images with links with Divi lightbox */
add_filter('the_content', 'divi_lightbox');
function divi_lightbox($content)
{
global $post;
$pattern = '#(<a.*href=".*\.(?:bmp|gif|jpeg|jpg|png)")(.*>.*<img.*>.*</a>)#i';
$replacement = '$1 class="et_pb_lightbox_image" title="' . $post->post_title . '"$2';
return preg_replace($pattern, $replacement, $content);