Skip to content

Instantly share code, notes, and snippets.

@EldarAgalarov
Last active July 11, 2018 05:40
Show Gist options
  • Save EldarAgalarov/9c8e8d26df3e4492d93ba3f92679aad1 to your computer and use it in GitHub Desktop.
Save EldarAgalarov/9c8e8d26df3e4492d93ba3f92679aad1 to your computer and use it in GitHub Desktop.
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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment