CSS edits on a live site

Recently I had cause to recode some CSS on a live textpattern site. With any CSS re-working there’s the inevitability of trying different methods to get things looking just right. Not the thing to be doing on a live site so here’s a plugin-free trick that might help.

It’s very simple. In Textpattern (or any CMS for that matter) I usually have one line calling the CSS for the site.

<txp:css format="link" n="default" />

But for this new work I’d really like textpattern to ignore me completely and serve my new CSS file. I can do this based on my location. Using whatismyip.com I can figure out my IP address eg: 50.90.5.80

Using the following PHP code I can get textpattern to serve that new CSS file instead of the default current style sheet.

<txp:php>
if($_SERVER["REMOTE_ADDR"]=="50.90.5.80")
{
echo "<txp:css format=\"link\" n=\"new_css_file\" />";
}
else {
echo "<txp:css format=\"link\" n=\"default\" />";
}
</txp:php>
comments powered by Disqus