Need to get attachment ID by Image URL
-
I’m using a jquery script called Captify, it works by taking the alt tag of an image and displaying it as the alt tag on mouse over.
I’m also using the header image theme plugin and this has no option to add or display the alt tag, and that’s fine as I can add the alt in the media browser.
What I therefore need is a way to get the attachment ID of the header image and display its alt.
The code below works, but this means I have to set the attachment ID manually (602). I’m sure my client wouldn’t want to do this so I’d like a way to make it dynamic. Are there any already-existing functions that I’m missing or should I create my own query?
<img src="<?php header_image(); ?>" class="captify" width="<?php echo HEADER_IMAGE_WIDTH; ?>" height="<?php echo HEADER_IMAGE_HEIGHT; ?>" alt=" <?php $alt_text = get_post_meta(602, '_wp_attachment_image_alt', true);print $alt_text; ?> " />
and the test site:
VC NewsThanks for any help!
Mark
- The topic ‘Need to get attachment ID by Image URL’ is closed to new replies.