Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use post title as featured image's alt text in Wordpress?

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!

like image 874
Alex Avatar asked May 09 '13 12:05

Alex


2 Answers

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) );
like image 98
user850010 Avatar answered Nov 06 '22 09:11

user850010


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.'" />
like image 32
kuldip Makadiya Avatar answered Nov 06 '22 09:11

kuldip Makadiya