To speed up my website in China I thought of hiding blocked services from Chinese users and wrote this and put it in functions.php

$isInChina = false; 
$ip = $_SERVER['REMOTE_ADDR']; // This will contain the ip of the request 
// This service tells me where the IP address is from and gives me more data than I need. 
$userData = json_decode(file_get_contents("http://www.geoplugin.net/json.gp?ip=".$ip)); 
if (is_Null($userData) || empty($userData) || $userData->geoplugin_countryCode == "CN")
    $isInChina = true; // Count no data as in China maybe to be paranoid. 

Shouldn't I store the result in some session level variable?

  • It's not clear what you're actually trying to block / where you want to use this information. Can you elaborate on that (in the question itself, preferrably in relations to WordPress).
    – kero
    Jan 9, 2019 at 12:05
  • If you haven't heard everything is blocked in China including DISQUS, Google, Facebook, Pinterest, Instagram etc. So if you have say the Twitter widget in your sidebar it won't work and it will slow your page load speed down drastically. So you have two options rip out all social media integration or hide it from users in China. I have tried both, the above code works, but it seems wasteful to call the geoplugin.net URL every time, shouldn't I cache the result in the session somehow?
    – Muskie
    Jan 9, 2019 at 12:36
  • 1
    I know this is not the comment you are hoping for, but the best method would be to make a second page for the chinese market. Not only, as you said, they have different restrictions, but also they have a extremely different marketing language than western countries.
    – marvinpoo
    Jan 9, 2019 at 12:51
  • The third option I have is remove all social media integration from the theme which is what I have running right now. It is fast and honestly my website is not popular. I will explore other options such as those listed below or that I have turned up by searching.
    – Muskie
    Jan 11, 2019 at 6:12

1 Answer 1


I'd recommend using something like this https://www.geoplugin.com/ and write an if statement for a either a display none or noscript. If you're looking for a good code base to start with I'd take a look at this answer. https://stackoverflow.com/a/13600004/3175165

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.