I had a situation recently where I needed to have a WordPress permalink redirect clients if they were an “authorized” IP address. Everyone else would get a 404.
An example of this would be if you had a super long URL that you wanted to keep private, but wanted an easy-to-remember URL to access it. You should be able to access it from home, but everyone else would see a 404. A quick way to remember a URL without sacrificing security.
Here’s how I did it. Add the following to functions.php for your site’s theme.
[snippet id=464 fontsize=14]
It breaks down to: if the page being requested is ID 100, and your client’s IP matches the dynamic DNS hostname IP in $ip, then you’ll get redirected to Google (or your super long, super secret URL). Otherwise, you’ll get your theme’s 404 page.
If you don’t have dynamic DNS setup for your house, then you can put in your home IP for $ip, instead of gethostbyname();. However, having dynamic DNS setup for your home’s IP is a good thing so that you can continue to authenticate without having to change the code everytime your ISP renews your IP.