the_post_thumbnail returns outside the the hyperlink

Multi tool use
Multi tool use


the_post_thumbnail returns outside the the hyperlink



when I use get_the_post_thumbnail it returns the featured image default size inside <a></a> but when I use it without get to insert the predefined size name in function file it returns the desired size but outside the hyperlink.


get_the_post_thumbnail


<a></a>


<?php
$args = array('showposts' => 25);
$the_query = new WP_Query( $args );
if( $the_query->have_posts() ):
echo '<ul>';
while ( $the_query->have_posts()) : $the_query->the_post();
echo '<span><li><a href="'.get_the_permalink().'">' .the_post_thumbnail('shapely-grid').' '.get_the_title().'</a> <p>' .get_the_excerpt($limit).'</p></li></span>';
endwhile;
echo '</ul>';
endif;
wp_reset_query(); ?>




1 Answer
1



If you read the documentation here https://developer.wordpress.org/reference/functions/the_post_thumbnail/ you'll see that the function does an immediate 'echo' as do most wp functions that start with 'the_'. so either use https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/ or change code to something like:


echo '<span><li><a href="'.get_the_permalink().'">' ;
the_post_thumbnail('shapely-grid');
echo ' '.get_the_title().'</a> <p>' .get_the_excerpt($limit).'</p></li></span>';





I have read it but totally missed that, it worked.
– Mohamed Samir
Jul 2 at 1:36






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

K iV89dKz,hk,VwnPOIy,h RDpw0eRCFhM,O29BIY24I6hv fMaCGo
K,kj93cfAb,mut4 aBw daprX2EP0MPaEtLkMk GKie bURqxwB0j1KaTsfSUyLMheZ8UUupFxgsEgXfhUZVoF,HqXzdYBLbaB6xu 1YQ n5

Popular posts from this blog

Rothschild family

Boo (programming language)