PrettyPhoto Auto Add Rel Tag for WordPress


/ Published in: PHP
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.