Restrict WordPress Admin Access to Specific IP Addresses
Explanation
To keep your WordPress admin area safe, you can limit access to only certain IP addresses. This means only people from these IPs can get into the admin dashboard or login page.
Here's how it works:
- Allowed IPs: You list the IP addresses that are allowed to access the admin area. Replace the example IPs in the code with your own.
- Visitor's IP: The code checks the IP address of anyone trying to access the admin area.
- Access Check: If someone tries to visit the admin dashboard or login page, the code checks if their IP is on your allowed list.
- Access Denied: If their IP isn't on the list, they see a message saying they can't access the page.
This method helps keep unwanted visitors out of your WordPress admin area by only allowing access from specific locations.
Code
Instructions
File Location: Add the following code to your theme's functions.php file or a custom plugin file.
Prerequisites:
- Ensure you have access to your WordPress files via FTP or a file manager.
- Have the IP addresses you wish to allow ready.
Implementation Steps:
- Open your WordPress installation directory and navigate to
wp-content/themes/your-theme-name/. - Locate the
functions.phpfile within your active theme's folder. - Make a backup of the
functions.phpfile before making any changes. - Edit the
functions.phpfile using a text editor. - Copy and paste the provided code snippet into the file.
- Replace the example IP addresses in the
$allowed_ipsarray with your own IP addresses. - Save the changes to the
functions.phpfile. - Upload the modified
functions.phpfile back to your server if you edited it locally. - Test the functionality by attempting to access the admin area from an allowed and a non-allowed IP address.
If you need assistance with implementation or require more advanced functionality, consider reaching out to wp-dude.com for expert WordPress support.