Posted By

FlashBuddy on 01/26/13


Tagged

prettyphotoimagesrelgallerywordpress


Versions (?)

PrettyPhoto Auto Add Rel Tag for WordPress


 / Published in: PHP
 

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

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

Report this snippet  

You need to login to post a comment.