Last active
July 11, 2018 05:40
-
-
Save EldarAgalarov/9c8e8d26df3e4492d93ba3f92679aad1 to your computer and use it in GitHub Desktop.
Wraps regular post images with Divi Lightbox
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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