Include Template Based on User IP Address
I need to prohibit certain IP Address from visiting my wordpress site. Hence i have used below code in my child theme function.php
add_action('template_include', 'restrict_user_access');
function restrict_user_access() {
$ipAddress = $_SERVER['REMOTE_ADDR'];
if($ipAddress === 'XX.XX.XXX.XXX') {
return "home/www/html/blog/wp-content/themes/theme-child/restrictusers.php";
}
}
}
I can able to load this template display the content for this IP whereas for other IP Address i get empty page.
Am i missing any?
My wordpress version is 4.9.10.
I also need to replicate this same process in other wordpress site v5.0.2.
Topic template-include Wordpress
Category Web