the_post_thumbnail
echoes its value, which doesn’t work in variable assignment. Use get_the_post_thumbnail
instead.
Most WordPress API functions follow this pattern, there are typically two versions – one which will echo
the result and another with get_
prepended which will return
the result.