Sean’s Obsessions

Sean Walberg’s blog

Telling Your Wordpress Environments Apart

I am doing some work with Wordpress, where we have a development server and a production server. The development side is set up as a git repo, and the production side pulls from the dev repo when we want to pull in changes:

1
git pull origin master

I move between the two environments using the host file, which sometimes means I’m not sure which environment I’m in. I put the following in functions.php to help me out:

1
2
3
4
5
6
7
8
9
function mysite_i_am_in_dev() {
  // Red border if we're in dev mode
  echo '<!-- dev mode -->
<style type="text/css"> body { border: 2px solid #FF0000; } </style>';
}
if ($_SERVER["SERVER_ADDR"] == "x.x.x.x") { // x.x.x.x is the IP address of your dev server
  add_action('wp_head', 'mysite_i_am_in_dev');
  add_action('admin_head', 'mysite_i_am_in_dev');
}

So now, anyone viewing the development server will have a small red border around the screen.

Comments

I’m trying something new here. Talk to me on Twitter with the button above, please.