Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
    
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

2 Answers 2

up vote 2 down vote accepted

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

alt="<?php  
$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.

share|improve this answer
    
Voila! Many thanks, that worked perfectly. –  Christopher May 20 '13 at 17:24

Try:

get_custom_header()->description
share|improve this answer
    
This doesn't work. The array returned from get_custom_header doesn't include a description key –  bungeshea May 20 '13 at 6:30

Your Answer

 
discard

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.