Improved custom post thumbnail function