PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, February 5, 2022

[FIXED] Returning current URL in WordPress

 February 05, 2022     php, return-value, url, wordpress     No comments   

Issue

I am trying to implement canonical and hreflang tags in WordPress, but I cannot retrieve the current URL of the visited page.

I tried :

 <?php echo site_url(); ?>

But it returns https://www.example.com instead of https://www.example.com/current-page1


Solution

In case anyone else needs this. Below code should get the exact URL including parameters.

home_url($_SERVER['REQUEST_URI']);

You can echo or return it depending on your use case. e.g.

echo home_url($_SERVER['REQUEST_URI']);

or

return home_url($_SERVER['REQUEST_URI']);


Answered By - Sadiq11111
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing