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.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)