Get URL of current page in PHP, WordPress, Joomla and Java Script

Many times you want to know the current page URL . Which is required many times like including images, stylesheet, including some jQuery plugin or using it for Facebook integration script etc.

Here i am going to tell you how to get the current page URL in PHP, WordPress, Joomla and Java Script.

PHP:-

$current_page_URL = $_SERVER[“SERVER_NAME”] . $_SERVER[“REQUEST_URI”];

Here $_SERVER[“SERVER_NAME”]  will give you the doman name of your site and $_SERVER[“REQUEST_URI”] will give you the rest

example:- for the URL http://http://www.7tech.co.in/php/get-url-of-current-page-php-wordpress/

$_SERVER[“SERVER_NAME”]   will give you 7tech.co.in

$_SERVER[“REQUEST_URI”] will give you /php/get-url-of-current-page-php-wordpress/

If you want to include Http or Https then add this condition

$current_page_URL =(isset($_SERVER[“HTTPS”]) && $_SERVER[“HTTPS”]==”on”) ? “https://” : “http://”;

$current_page_URL = $_SERVER[“SERVER_NAME”] . $_SERVER[“REQUEST_URI”];

 

WordPress:-

the_permalink()

This function returns you the link of the current page or post. If this function is used inside a WordPress loop than it will return the link of the current post inside the loop.

Alternatively you can use the $_SERVER[“SERVER_NAME”] . $_SERVER[“REQUEST_URI”] also.

get_bloginfo(“siteurl) it will return you the blog url set in the wordpress->Settings->General

 

Joomla:-

You can use the Joomla API to find the current URL of the page.

JURI::current()

This will return current page URL.

JURI::base()  this will return you the base URL of your Joomla Site.

 

Java Script:-

window.location

It will return you current page url in Java Script.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Privacy Policy · Contact · Sitemap

© 7Tech – Programming and Tech Tutorials