Return to Snippet

Revision: 61987
at January 26, 2013 01:46 by FlashBuddy

Initial Code
 * Add autmatically rel="prettyPhoto" attribut when you have one image in a post
 * or rel="prettyPhoto[0]" attribut when you have more than one image in a post
function sumtips_image_attribute($content) {
       global $post;
       $pattern ="/<a(.*?)href=('|\")(.*?).(bmp|gif|jpeg|jpg|png)('|\")(.*?)>/i";
       $replacement = '<a$1href=$2$3.$4$5 rel="prettyPhoto">';
       $content = preg_replace($pattern, $replacement, $content);
       return $content;
add_filter('the_content', 'sumtips_image_attribute');

Initial URL

Initial Description
Auto add rel="prettyPhoto" or rel="prettyPhoto[group] to WordPress href image links.

Initial Title
PrettyPhoto Auto Add Rel Tag for WordPress

Initial Tags

Initial Language