/ Published in: PHP
Auto add rel="prettyPhoto" or rel="prettyPhoto[group] to WordPress href image links.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/** * 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">'; return $content; } add_filter('the_content', 'sumtips_image_attribute');