Get Permalink without domain (i.e. get relative permalink) [duplicate]

Use $_SERVER['REQUEST_URI'] instead of get_permalink() to grab the current URL. get_permalink will give you the full address of the current post, not the address of the URL visited.

e.g. for example.com/test/page echo $_SERVER['REQUEST_URI']; prints /test/page

Note that this doesn’t include the hashtag, as that part never gets sent to the server, and it also doesn’t include ?foo=bar type parameters, those are in the $_GET array.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)