Ok, I think I figured it out.
In my case my blog was setup under shorter version of domain https://domain.tld/
while <?php echo $_SERVER["SERVER_NAME"]; ?>
was returning www.domain.tld
After changing my nginx setup from:
"server_name www.domain.tld domain.tld;"
to:
"server_name domain.tld www.domain.tld;"
it worked fine.
I hope it helps.