Shortcode hiển thị IP người dùng

Cập nhật lần cuối 18/03/2015 by trong WordPress vào 18/03/2015 có 875 Views

Dưới đây là shortcode wordpress để hiển thị IP người dùng. Bạn hãy thêm đoạn code sau vào file functions.php trong theme bạn đang nhé.

// Display User IP in WordPress
function get_the_user_ip() {
if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {
//check ip from share internet
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
//to check ip is pass from proxy
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
return apply_filters( 'wpb_get_ip', $ip );
}
add_shortcode('show_ip', 'get_the_user_ip');

Để hiển thị bạn thêm shortcode [show_ip] vào nơi muốn hiển thị IP nhé 🙂

Chúc các bạn thành công!
Tham khảo: http://www.alltechguide.net/show-visitors-ip-address-wordpress-without-plugin.html

5/5 - (2 votes)
  • Bình luận
Sản phẩm nổi bật của Toản
x