Simple function not working on frontend and can’t figure a way to debug it

loop_start is too late

template_redirect did the trick.