Last active
October 9, 2016 16:30
-
-
Save Bobeta/223e8ab1521c551c04cf0cd83f98d862 to your computer and use it in GitHub Desktop.
WP Add rel=”lightbox” to all images embedded in a post
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
<?php | |
// Add lightbox to all images embedded in a post | |
add_filter('the_content', 'my_addlightboxrel'); | |
function my_addlightboxrel($content) { | |
global $post; | |
$pattern ="/<a(.*?)href=('|\")(.*?).(bmp|gif|jpeg|jpg|png)('|\")(.*?)>/i"; | |
$replacement = '<a$1href=$2$3.$4$5 rel="lightbox" title="'.$post->post_title.'"$6>'; | |
$content = preg_replace($pattern, $replacement, $content); | |
return $content; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment