Skip to content

Instantly share code, notes, and snippets.

@chrdesigner

chrdesigner/function.php

Last active Aug 29, 2015
Embed
What would you like to do?
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
You can’t perform that action at this time.