Earth Hour is quickly approaching, this year’s date, March 27th at 8:30pm. Well the team at Brave New Code wrote a fantastic WordPress plugin that will turn your site “off” for earth hour. This is great if your site is ran by WordPress. My problem, only my blog is WordPress everything else is custom code.
My Solution was to modify their script to a simple php file. Basically it does the same thing as the plugin but outside of WordPress. The download also replaces your site with a message letting the user know that it’s Earth Hour.
You can download your copy of my script here.
Or get the original WordPress plugin here.
THE SOURCE:
Don’t want my code just add this to your site’s header or wherever you want the earth hour to be displayed.
If you’re not in GMT set your offset with $GMT_offset.
You may also echo out $earth_hour_minutes for the amount of minutes left in Earth Hour.
// Basic time settings $GMT_offset = "0"; $start_time = gmmktime( 20, 30, 0, 3, 27, 2010 ); $end_time = $start_time + 60*60;</pre> // adjust for local time $adjusted_time = time() + $GMT_offset*60*60; $in_earth_hour = ( $adjusted_time >= $start_time && $adjusted_time <= $end_time ); $earth_hour_minutes = ($end_time - $adjusted_time)/60; if ($in_earth_hour){ //Do this during earth hour die(); //stop the rest of your site from running }