Update template-tags.php

Changed as per code on https://gist.github.com/jeffreyzinn/7e7734093ea944c7e2ce with differences accounted for