Get Current Page URL (Context) for WordPress


/ Published in: PHP
Save to your folder(s)

This script will return the URL for the current page you're on, including category and tag pages.


Copy this code and paste it in your HTML
  1. <?php
  2. function curPageURL() {
  3. $pageURL = 'http';
  4. if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
  5. $pageURL .= "://";
  6. if ($_SERVER["SERVER_PORT"] != "80") {
  7. $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
  8. } else {
  9. $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
  10. }
  11. return $pageURL;
  12. }
  13. ?>
  14.  
  15. <?php echo curPageURL(); ?>

URL: http://dailypaste.wordpress.com/2008/10/26/php-get-current-url/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.