How to rotate your logo on holidays.
One of the most interesting things I see Google do regularly is change their logo to celebrate the holidays or mark a special day. It seems like a pretty labor intense operation but it’s actually a very simple thing to do with a little bit of PHP and it works great for WordPress blogs as well.
Now, the first thing you’d need to do in order to change your logo is store it in a specific folder and call it based on the day.
<img src=’/path/to/your/images/filename-<?php date(‘Y-m-d’);?>.jpg’ alt=’logo for <?php date(‘Y-m-d’);?>’/>
This example shows a very simple method to accomplish our goals here. It simply inserts the value for a date (in this case 2008-01-01) into the file name which will cause the server to load the image filename-2008-01-01.jpg from your website. In theory this is all we need to do but … it means that you will have to save 365 versions of your logo per year and edit the ones that you want to make special which is time consuming. Let’s look at a better method for completing this objective.
We want to introduce the option of placing the standard logo on most days as a failsafe and only display the special logos on special days. To do this, we need to check if the file exists, otherwise fall back to the original.
<?php
if(file_exists(‘/path/to/your/images/filename-’.date(‘Y-m-d’).’.jpg’)) {
$file = date(‘Y-m-d’);
} else {
$file = ’standard’;
}
?><img src=’/path/to/your/images/filename-<?php echo $file;?>.jpg’ alt=’logo for <?php date(‘Y-m-d’);?>’/>
Now what we’ve done is called the file_exists function to ensure the logo filename-2008-01-01.jpg exists before showing it. If it doesn’t exist, it shows the logo filename-standard.jpg instead.
P. S. You may want to take a look at my tutorial on caching WordPress as this process will increase server load.






This is perfect, I was jsut thinking the other day about the holidays coming up and how to easily tweak some stuff on my sites.
Thanks Chris!!!
JR
[...] feel free to subscribe to my RSS feed or leave a comment.The other day I wrote a tutorial on how to rotate your logo on holidays and since then I’ve had a few people email me and ask how to this specifically for WordPress [...]
nice way , this will allow me do as google ” automated rotation ” but why you talked at the end about cashing wordpress ? it will make extra load on the server ?
Money Academy’s last blog post..Feedburner problem while posting my feed url