Created
November 17, 2012 22:27
-
-
Save ataylorme/4100771 to your computer and use it in GitHub Desktop.
add rel="prettyPhoto" to images in the content
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
//start function to add rel attribute to image links | |
function rel_prettyPhoto($link) { | |
global $post; | |
$find ="/<a(.*?)href=('|")(.*?).(bmp|gif|jpeg|jpg|png)('|")(.*?)>/i"; | |
$replace = '<a$1href=$2$3.$4$5 rel="prettyPhoto['. $post->ID .']" $6>'; | |
$link = preg_replace($find, $replace, $link); | |
return $link; | |
} //end function to add rel attribute to image links | |
//add rel attribute function to the content filter | |
add_filter('the_content', 'rel_prettyPhoto'); | |
//add rel attribute function to the attachment link filter | |
add_filter('wp_get_attachment_link', 'rel_prettyPhoto'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment