Advertisement
miriamdepaula

WordPress: Custom class and rel to attachments

Feb 5th, 2012
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.50 KB | None | 0 0
  1. <?php
  2. //add custom class to attachment image
  3. add_filter('get_image_tag_class','add_image_class');
  4. function add_image_class($class){
  5.     $class .= ' attachment';
  6.     return $class;
  7. }
  8.  
  9. //add rel attribute to attachment link
  10. add_filter('wp_get_attachment_link', 'add_rel_to_attachments');
  11. function add_rel_to_attachments($link) {
  12.     global $post;
  13.     //check if rel already exists
  14.     if (strpos($link, ' rel="') == false)
  15.         return str_replace('<a href', '<a rel="lightbox" href', $link);
  16.     else
  17.         return $link;
  18. }
  19. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement