the_post_thumbnail_url() will echo the URL. You should use functions that have get_the_… in the beginning of their names, since functions starting with the_… will generally echo the content. So, your sprintf should use get_the_post_thumbnail_url() like this: $html .= sprintf( ‘<div class=”grid-item”><a href=”https://wordpress.stackexchange.com/questions/278102/%s” title=””>%s</a></div>’, get_the_post_thumbnail_url( get_the_ID(), ‘full’ ), the_title_attribute( ‘echo=0’ ), //get_the_title() //the_post_thumbnail() ); However, in … Read more