I have created a page template where I need current page URL

I have tried




but it shows nothing.

Let me know is anything missing in code.


if you're using a page template, then if you want to get the current page URL you could try to use this function:



echo get_permalink();

if you want to print the result


You can get page url like this.

global $post;
echo get_permalink( $post->ID );

Hope it helps :)

  • $post may be overwritten by a secondary query, in this case get_queried_object() is safer and avoids accessing globals directly. – Milo Jul 30 '16 at 15:40
  • global variable must not be overwritten that's the bad practise. – ma_dev_15 Aug 1 '16 at 4:31
  • Using the API overwrites $post, that's how the_post works. Use API functions when available rather than relying on global variables. – Milo Aug 1 '16 at 14:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.