O'Brien Labs

  • Home
  • Portfolio
  • WordPress
    • Plugins
    • WordPress Tips
  • Random Post
  • About

Keyboard Shortcuts

R - Load a random post.
? - Open this dialog window.
O'Brien Labs > Archives for WordPress > WordPress Tips Keyboard Shortcuts

WordPress – Only logged in users can view your website

March 18, 2016 by Pat 12 Comments

I had a WordPress site requirement where only logged in users could see the site and it’s contents. I came across this bit of code a few years ago and found it to be helpful. Place it into your functions.php and when a visitor comes along who is not logged in, it’ll redirect them to the wp-login.php page to login. Once logged in, then they can view the site without being blocked. This is an example where it can help keep unwanted visitors away from the content of your site. It’s been working great and I wanted to share it.

WordPress – Redirect based on IP or return 404

October 13, 2015 by Pat 3 Comments

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. 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 [Read More…]

WordPress – Accessing external database

December 23, 2014 by Pat 1 Comment

I wanted to post this quick tip on how to access an external database, or an external table, from within WordPress. This is mostly here for my reference in case I need it in the future. Hopefully it helps you out, too. I have a table that’s external to my primary WordPress installation that I needed to get some information out of. In my functions.php, I added this piece of code into a function I already had, and it worked great. It’s a simple bit of code that just counts the number of entries in the “data” table. This snippet uses the the database login and password information from your wp-config.php. If you need to specify different login information, just change the DB_USER and DB_PASSWORD to [Read More…]

About

The purpose of this site is for me to share my DIY technical experiences as a place to document them publicly. Hopefully somewhere along the way they are helpful for you.

Recent Posts

  • BelchertownWeather.com website theme for weewx
  • How to setup your own MQTT Broker
  • Nest Thermostat Push Notifications
  • mailx – Send automated Linux email with gmail
  • simplemonitor – who watches the Nagios watchman?

Tags

ad adblock amp Asterisk AutoHotKey battery block Camera car code codesnips database developer Emergency halloween Heat Home Inverter Linux load Nagios night plugins portfolio Power Project Raspberry Pi simplemonitor snippets Tech Tips Timelapse tips Tutorial ublock vision Weather Station webcam website weewx WordPress

Copyright © 2010–2019 O'Brien Labs – All Rights Reserved – Use without permission is illegal.

Please support this website by adding us to your whitelist in your ad blocker. Ads are what helps us bring you premium content! Thank you!