Skip to content

Instantly share code, notes, and snippets.

@ataylorme
Created November 17, 2012 22:27
Show Gist options
  • Save ataylorme/4100771 to your computer and use it in GitHub Desktop.
Save ataylorme/4100771 to your computer and use it in GitHub Desktop.
add rel="prettyPhoto" to images in the content
//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