Been hunting for a while and I can't figure out how to use get_custom_header to get the alt text associated with the media file, so that I can add photo credits to the headers on my site. Am I missing something?

Code to add header image is:

<img src="<?php header_image(); ?>" height="<?php echo get_custom_header()->height; ?>" width="<?php echo get_custom_header()->width; ?>" alt="" />

The get_custom_header function doesn't seem to have a way to pull in the alt text.

  • Maybe you should tell us what you've done so we can tell you what you might have missed ;) – jfacemyer Mar 6 '13 at 16:00
  • 1
    Added a little more detail if that helps. – Christopher Mar 6 '13 at 16:08
  • Interested to know whether the answer helped...I'm not certain that it's valid, and would like to know if this works! – jfacemyer Mar 7 '13 at 16:23

Use this for the alt="" attribute on the custom header <img> tag …

$attachment_id = get_custom_header()->attachment_id;
$alt = get_post_meta( $attachment_id, '_wp_attachment_image_alt', true );
if ( count( $alt ) ) echo $alt;
?>" />

… and then just edit the media attachment and add the alt text.

| improve this answer | |


| improve this answer | |
  • This doesn't work. The array returned from get_custom_header doesn't include a description key – shea May 20 '13 at 6:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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