10/2/17

Get the Current Page URL

This function simply returns the URL of the current page.The URL is returned with its protocol and TCP port number. I’ve added a shortcode just incase you need to return it within your page or post content.


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") { $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"]
.$_SERVER["REQUEST_URI"]; } else { $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; } return $pageURL; }

Usage

In php code:  <?php if (function_exists(‘get_current_page_url’)) echo get_current_page_url(); ?>

Shortcode in post or pages:  [geturl]
Bạn đang đọc bài viết Get the Current Page URL tại Website: Học Lập Trình

0 nhận xét: