Back to Top

How to get Current URL in WordPress?

To get Current URL in wordpress

After a long time, I get time for the article so today i am going to explain how to get current URL on which page you are.

I am going to show you function which will you can use on any page and get URL of page in WordPress function.

So, Let’s see the function:

function current_url() {
    $pageURL = 'http';
    if( isset($_SERVER["HTTPS"]) ) {
        if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
    }
    $pageURL .= "://";
    if ($_SERVER["SERVER_PORT"] != "80") {
        $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
    } else {
        $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
    }
    return $pageURL;
}

You can use above function in PHP also. You will get current URL of page. This is very simple function, you can just copy and paste and use it.

Must Read:

Table layout using DIV tags
Clean HTML content in PHP
The DocType In HTML

As always, thanks for reading. Don’t Forget to Follow us on Twitter or Subscribe us to Get the Latest Updates.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Most Popular Posts

What are Traits in PHP

Posted on 4 years ago

Bhumi

How to import user from CSV in WordPress?

Posted on 5 years ago

Bhumi

How to use HTML5 AutoFocus attribute

Posted on 4 years ago

Bhumi

How to use Web service in WordPress?

Posted on 5 years ago

Bhumi

Hello world

Updated 1 month ago

Nick Carter

In depth Understanding of Laravel Core

Updated 3 months ago

Bhumi

ECMAScript 6 New Features – 2

Updated 1 year ago

Bhumi

The Reader’s Poll – June 2015

Posted on 4 years ago

Bhumi

The Reader’s Poll – August 2014

Posted on 5 years ago

Bhumi

The Reader’s Poll – June 2014

Posted on 5 years ago

Bhumi

The Readers’ Poll – May 2014

Posted on 5 years ago

Bhumi

The Readers’ Poll – August 2013

Posted on 6 years ago

Bhumi