I am working on a site built on Wordpress and the single post template calls the featured image using the below line of php.
<?php $img = array('class' => 'enigma_img_responsive', 'alt' => 'the alt', 'title' => 'the title' );
if(has_post_thumbnail()):
the_post_thumbnail('home_post_thumb',$img);
endif; ?>
I am trying to get this code to pull the alt and title from the media library dynamically for all featured images. From what I have seen you can't use other php inside of the array where I could list the attributes and there values. I've tried the following as a potential solution but it doesn't work.
<?php $img = array('class' => 'enigma_img_responsive', 'alt' => 'featured imag for the_title();', 'title' => 'the_title();' );
if(has_post_thumbnail()):
the_post_thumbnail('home_post_thumb',$img);
endif; ?>
The output for the above code is having "the_title();" actually show up in the alt and title attributes.
Is there a workaround for this, can't seem to find one. I assume there is since WordPress is so popular.
'title' => the_title();
or useget_the_title()
instead ofthe_title()
– Vincent G