Please check the screenshot, let me know how to fix this issue…And you can see there’s no image alt data in HTML. Another thing is that if I use PHP in img src so I can’t set width & height like (300 x 300). The output is a full-size image and if I use a static URL in img it works fine, how to deal with that?
<nav id="nav-single"> <?php $prev_post = get_previous_post(); $id = $prev_post->ID ; $permalink = get_permalink( $id ); $thumbnail = get_the_post_thumbnail( $id ); $image_alt = get_post_meta($thumbnail, '_wp_attachment_image_alt', true); ?> <div class="pexel-previous-post-data"> <div class="pexel-previous-post-img"> <a href="<?php echo $permalink; ?>"> <img src="<?php echo $thumbnail; ?>" alt="<?php echo $image_alt; ?>" width="300" height="300"> </a> </div> <div class="pexel-previous-post-Text"> <span class="nav-previous"><?php previous_post_link( '%link', __( '<span class="meta-nav">←</span> Previous', 'twentyeleven' ) ); ?> <h5 class="pxl_head--h5"><a href="<?php echo $permalink; ?>"><?php echo $prev_post->post_title; ?></a> </h5> </span> </div> </div> </nav>
Advertisement
Answer
Use get_the_post_thumbnail_url()
to get post image url as get_the_post_thumbnail()
returns html with img
tag. get_the_post_thumbnail_url()
will return only image url.
$thumbnail = get_the_post_thumbnail_url( $id );