Couple of issues are seen here –
- You have hooked a function in a template file whereas such code should go in
functions.php
instead or you can directly put the code of this function in the template. - You does not seem to be getting value of
$post
inside this function. - Both the
return
statements should be removed and justecho $html;
should be placed just after thewp_reset_postdata()
in your current code.