Is there any function that gets the URL of the current page I am viewing on my WordPress blog?
All that I found was Boolean functions that check if the page is the homepage/category/single post/etc’ and now the exact page that is viewed.
Edit: There is a function that gets posts URL – get_permalink(). I need one that gets index / category / ect’ pages too.
Thank you,
Hatzil.
Here is a handy snippet with which you can easily get current URL on your WordPress website. It doesnât matter if you need it on single post, page, home, category, tag, custom post type or any other WordPress template.
You can use this piece of code inside any template on your WordPress website:
Here is a snippet from my code:
The
set_url_scheme
looks overkill: it’s very easy to get the scheme without it. However, there is a hook there, so it brings some flexibility. And standardization.