Skip to content

Instantly share code, notes, and snippets.

@chrdesigner
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrdesigner/14ab0e9c77ef653a8f75 to your computer and use it in GitHub Desktop.
Save chrdesigner/14ab0e9c77ef653a8f75 to your computer and use it in GitHub Desktop.
add rel prettyphoto to all images
<?php
/* add rel prettyphoto to all images */
function autoadd_rel_prettyPhoto($content) {
global $post;
$pattern = "/(<a(?![^>]*?data-rel=['\"]prettyPhoto.*)[^>]*?href=['\"][^'\"]+?\.(?:bmp|gif|jpg|jpeg|png)['\"][^\>]*)>/i";
$replacement = '$1 data-rel="prettyPhoto['.$post->ID.']">';
$content = preg_replace($pattern, $replacement, $content);
return $content;
}
add_filter("the_content","autoadd_rel_prettyPhoto");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment