WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

For single posts and pages, I would like to add certain rel attributes to all the images on the contained therein added with the "Add Image" functionality on the edit screen.

The attribute would be rel="lightbox[post id]"

What function would I filter to accomplish this most effectively?

share|improve this question
up vote 2 down vote accepted


function insert_img_rel_attrib( $html, $id, $caption, $title, $align, $url, $size, $alt )
  /* Run your magic on the image $html to insert rel attrib */
  return $html;
add_filter( 'image_send_to_editor', 'insert_img_rel_attrib' );
share|improve this answer

The rel="whatever" attribute is only for search engines. If you consider to make your content "better" for spiders, crawlers and such, take a look at this list first.

share|improve this answer
@kaiser: nope. w3.org/TR/html401/struct/links.html#adef-rel - semantically fine for relating a lightbox gallery of images. – two7s_clash May 23 '11 at 21:59
@two7s_clash: Jes, take a look at the link behind the link to provided: w3.org/TR/html401/types.html#type-links – kaiser May 23 '11 at 22:03
@kaiser: I see "Authors may wish to define additional link types not described in this specification." I'll be sure to add my usage in a profile. :) FYI, this is a quite common, practical, and working useage of rel tags. I invite you to find real word examples of some of these "recognized link types." At the end of the day, these are just recommendations and to say that the rel attribute is only for search engines is just plain wrong. – two7s_clash May 23 '11 at 22:11
"Wrong" is a pretty harsh term in this context. Aside from canonical and nofollow nothing is official, but I'd stick to those terms that are most common: next, prev, last, first, attachment, up, top, etc. – kaiser May 23 '11 at 22:15
@kaiser: Sorry, not meaning to be harsh. I just don't understand for what real world reason you would advocate just sticking to those terms? – two7s_clash May 23 '11 at 22:43

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.