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

I need to call the alt tag for images on my site dynamically. The only thing I can find online is to use the post title function but that doesn't really help me out.

share|improve this question
Can you provide a bit more detail? What images do you want to provide dynamic ALT tags? What dynamic data do you want to provide as ALT tags? – Chip Bennett Jun 22 '11 at 14:18

I believe the alt attribute of the image is stored in post_content, isn't it?

To get the alt tag for an image with attachment ID $attachment_ID, you would just call:

$alt_text = get_post( $attachment_ID )->post_content;

To actually display the alt text dynamically on images that are already embedded in posts, you would have to do some heavy regex processing on the_content filter.

If you wanted to set it dynamically when adding the image to a post, I would add a filter on image_send_to_editor.

share|improve this answer

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.