0

i saw a interesting post on Stackoverflow where someone showed a code to to use the post title als alt tag for the featured post. So i tried to use the code for myself and change it a bit because mine differs a bit.

Original Code

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

I changed it to

<?php $title=get_the_title(); the_post_thumbnail( array($size),array( 'alt' =>$title) ); ?>

The problem is that $size is not working correctly anymore it came out with 150px x 150px. (My original code is <?php the_post_thumbnail( $size ); ?> )

I hope that someone could tell me what is wrong with it =o

1

If $size is already an array in your original code as it looks to be, then the argument passed will become array(array(150,150)) instead of just array(150,150) and fail, so you can just do:

<?php $title=get_the_title(); the_post_thumbnail( $size, array( 'alt' =>$title) ); ?>
  • 1
    Thank you so much. This is working fine.. also thanks for the information with the array =), i wish you a great day (because my is now saved) – Deex Jun 13 '16 at 5:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.