Format Titles for Localhost

December 13, 2010 – 10:54 pm

If you’ve ever worked on your own personal web server and a remote server at the same time, then you’ve probably had the same files on both at the same time as well. With multiple open browser tabs/windows with duplicate titles, it can be difficult to tell at a glance whether you’re looking at a locally hosted page or a remotely hosted page.

There’s an easy way to automatically format your titles so that you can quickly see where your page is being hosted. Follow the simple code below to format your titles.

localhost

In your HTML code where you normally have <title>My Homepage</title>, instead, copy and paste this line:


<title><? $servername = $_SERVER['SERVER_NAME']; echo ($servername=="localhost") ? "{Localhost}" : ""; ?> My Homepage</title>

Change “Localhost” and “My Homepage” to read anything you’d like (Sandbox, Testing Environment, etc). This works great inside your WordPress template as well (header.php).

icon

0 Comments

    Add a Comment