Posted By

jakepaint on 08/05/08


url headers wordpress functions

Versions (?)

Who likes this?

4 people have marked this snippet as a favorite


Wordpress get URL

 / Published in: PHP

URL: none

This function gets the exact string that shows in the address bar. If you use it with no arguments, function will simply return the string, if you put TRUE as the argument, the function returns a html link to the current url. This works whether you are on a post or a page. It strips any other query information like searches.

  1. function url_is($showlink = FALSE) {
  2. if ($_GET['page_id'])
  3. $query = 'page_id=' . $_GET['page_id'];
  4. else
  5. $query = 'p=' . $_GET['p'];
  6. $urlis = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF'] . '?' . $query;
  7. if($showlink == TRUE)
  8. return '<a href="' . $urlis . '">' . $urlis . '</a>';
  9. else
  10. return $urlis;
  11. }

Report this snippet  


RSS Icon Subscribe to comments
Posted By: BredeBS on May 15, 2010

This work only if you don't have Friendly URL, just return or something like that. [Bad Engrish?]

You need to login to post a comment.