How to Whitelist IP Address on WordPress Website?

Table of Contents

To whitelist IP addresses in WordPress, you can use a security plugin like Wordfence or a custom code in your theme’s functions.php file.

Using Wordfence:

  1. Install and activate the Wordfence plugin.
  2. Go to the Wordfence menu in the WordPress dashboard and click on the “Firewall” tab.
  3. Scroll down to the “Whitelisted IP addresses” section and click “Add IP” to add the IP addresses you want to whitelist.

Using custom code:

  1. Connect to your WordPress site using FTP or File Manager in cPanel.
  2. Open the functions.php file of your theme in a code editor.
  3. Add the following code at the end of the file, replacing the example IP addresses with the ones you want to whitelist:
function whitelist_ip_addresses() {
   if (in_array($_SERVER['REMOTE_ADDR'], array('IP_address_1', 'IP_address_2'))) {
       return true;
   }
}
add_filter('pre_option_require_name_email', 'whitelist_ip_addresses');
  1. Save the file and upload it to your server.

With either method, the specified IP addresses will be allowed to access your site and bypass any security measures in place, so use caution when whitelisting IPs.

Join Our Community

Subscribe to Go With Blogs for regular updates.

You may be interested in