0

I want to insert html in php code but the problem is this html portion already contain php code. Below is the wrong code can any body correct it??

<?php
 if (isset( $metro_creativex_feat_image[0] )) :
  echo ' <a href="<?php the_permalink(); ?>"><div class="img">' . get_the_post_thumbnail() . '</a></div>';
  endif;
?>

3 Answers3

0

You have the second half correctly, you just needed the permalink bit fixed by coming out of the string like so:

echo ' <a href="' . the_permalink() . '"><div class="img">' . get_the_post_thumbnail() . '</a></div>';
delboy1978uk
  • 12,118
  • 2
  • 21
  • 39
0

Hi please try the below

<?php
    if (isset( $metro_creativex_feat_image[0] )) :
        echo ' <a href="' . the_permalink() . '"><div class="img">' . get_the_post_thumbnail() . '</a></div>';
        endif;
?>

You have appended the result of the get_the_post_thumbnail function so you need to append the result of the the_permalink function as well.

0

Ma'am, please replace below script with your existing one.

<?php
if( isset($metro_creativex_feat_image[0]) ) {
    echo '<a href="'.the_permalink().'"><div class="img">' . 
get_the_post_thumbnail() . '</div></a>';
}
?>
Jimmy
  • 11
  • 4