Take the 2-minute tour ×

I want to use Featured Images (thumbnails) in my posts.

The thing is, I want to be able to change the following image attributes after the image has been attached to the post, but before the post has been published:

Title Alternate Text Caption Description

How do you do that?

share|improve this question
Perhaps if you could explain what your intention is? –  Dominic Oct 31 '11 at 10:23
When I make a new post, I attached a Featured Image, then I check a bunch of Taxonomies, then I create a title for the post using the checked taxonomies. All that is working, and was done in the function.php file. Now - when I create the post title, I want to change the Featured Image's Title, Alt Text, Caption, Description to that created post title. –  Dave Tras Oct 31 '11 at 15:09
add comment

3 Answers


$size = array(150,150);

$default_attr = array(
            'src'   => $src,
            'class' => "attachment-$size",
            'alt'   => trim(strip_tags( wp_postmeta->_wp_attachment_image_alt )),

the_post_thumbnail( $size, $attr ); 

share|improve this answer
From what I understand, this is creating a var array called $attr, which stores the src, class, alt, title. The question I have is: what about the Caption and Description, and how do you replace these? –  Dave Tras Oct 31 '11 at 15:25
I hope this will help you out devmate.net/blog/wordpress-images-metadata –  OpenCode Nov 1 '11 at 9:29
should $default_attr be just $attr? –  klamping Feb 18 '12 at 16:36
add comment

I'm still not clear what you're trying to do.

This will display the featured image in your markup using the post title as alt and title attributes.

$image_meta = wp_get_attachment_image_src( get_post_thumbnail_id(), 'medium'); 
// replace 'medium' with 'thumbnail', 'large', or 'full'.
echo '<img src="'.$image_meta[0].'" alt="'.$post->post_title.'" title="'.$post->post_title.'" width="'.$image_meta[1].'" height="'.$image_meta[2].'"/>';

If you want to actually change the featured image title, alt, caption, description etc in the database, then you could look at the post_publish hook. This should get you started:

function do_stuff($post_ID){
    global $post;
    $post_thumbnail_id = get_post_thumbnail_id($post_ID);
    if ($post_thumbnail_id){
        // Do Stuff with your featured image id - $post_thumbnail_id
return $post_ID;
add_action('publish_post', 'do_stuff');
share|improve this answer
add comment

try this and its work fine.

$title_attribute = the_title_attribute( array( 'echo' => FALSE ) );
        'alt'   => $title_attribute, 
        'title' => $title_attribute 
share|improve this answer
add comment

Your Answer


