fbpx

Not much to this one. Go

[current_url]

in your page or post to output the page’s URL, or in php:

echo dje_current_url();

Here’s the code to put in your plugin or your Child Theme’s functions.php.

// Output URL of Current Page, including port if it isn't 80
add_shortcode ('current_url', 'dje_current_url');
function dje_current_url() {
	$URL = 'http';
	if( isset($_SERVER["HTTPS"]) ) {
		if ($_SERVER["HTTPS"] == "on") {$URL .= "s";}
	}
	$URL .= "://";
	if ($_SERVER["SERVER_PORT"] != "80") {
		$URL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
	} else {
		$URL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
	}
	return $URL;
}