Skip to main content

Had a request last week to create a shortcode that would output the current page URL within a post or page in WordPress.

Here you go, edit your /wp-content/themes/themeName/functions.php file and add this to the bottom:

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

All set!  Now on the page or post drop in:


Leave a Reply