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

How do I add post title as alt tag in a post? I tried using array(title => '.the_title.') but it didnt work. I think I am not suppose to use the_title. I tired using get_the_title as well.


share|improve this question
Where exactly do you need an alt attribute? Note, there is no alt tag. – toscho Jul 10 '12 at 9:10

@its_me got it almost right. Those args must be 2nd resp. 3rd Parameter, not first:

$attr = array(
    'title' => 'howdy partner',
    'alt'   => 'a nice view of the ocean',

// pick one, note 2 or 3 arguments:
the_post_thumbnail( 'post-thumbnail', $attr );

echo("<a href='$p->permalink'>". // null for current $post->ID (use within loop)
    get_the_post_thumbnail( null, 'post-thumbnail', $attr ).
share|improve this answer

Try using this <?php the_title(); ?>

Here is example -

<img src="http://link-to-image" title="Image title" alt="<?php the_title(); ?>"/>

share|improve this answer
rather use the_title_attribute() codex.wordpress.org/Function_Reference/the_title_attribute – Michael Jul 10 '12 at 9:54

What code does your theme use to show the featured image (aka post-thumbnail)? Most themes do it like this:

<?php the_post_thumbnail(); ?>

or like this (the right way to do it):

    if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.

In that case, replace the code with this:

    if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
                'alt' => trim( strip_tags( $attachment->post_title ) ),

...where, 'alt' => trim( strip_tags( $attachment->post_title ) ) tells the the_post_thumbnail function that it should use the post's title instead of image's alt text.

READ: WordPress Codex — Function Reference for the_post_thumbnail

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.