6
votes

How can I use post title as the alt text of that posts featured image in Wordpress?

please show me how/where can I tweak the WordPress core files to achieve that, since it seems that the theme I'm using now doesn't react in any way to plugins that re-write the alt tags of images...

Thank you!

2

2 Answers

8
votes

No need to change WordPress core files:)

Just locate in your theme where the_post_thumbnail() function is used and change it to:

$title=get_the_title();
the_post_thumbnail( array(150, 150),array( 'alt' =>$title) );
3
votes

user850010

You are absolutely right .

$title=get_the_title();
the_post_thumbnail( array(150, 150),array( 'alt' =>$title) );

this is usefull of you Alex please check it out.

Alex , if you want to display only specific image then use this code

<img src="'.wp_get_attachment_url( get_post_thumbnail_id($item->ID)).'" alt="'.$item->post_title.'" title="'.$item->post_title.'" />