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
- Bình luận