Post Pic

How to: Wish your reader a merry Christmas

It’s Christmas today! So what about wishing merry Christmas to your readers? In this simple recipe, we’ll see how easy it is to implement a “Merry Christmas” message in your WordPress blog.

To achieve this very simple recipe, simply paste the following code anywhere on your theme. The "Merry Christmas" message will be displayed only on Christmas day.

<?php
if ((date('m') == 12) && (date('d') == 25)) { ?>
    <h2>Merry Christmas from WpRecipes!</h2>
<?php } ?>

By the way, I wanted to wish a Merry Christmas to all of you, and saying a big THANK YOU for your support and readership!

11 Responses

Dec 25 2008 10:24

if ((date(‘m’) == 12) && (date(‘d’) 25)) { ?>
Missed the ‘==’ in the second condition?

Dec 25 2008 10:37

Damn, you were right! I should avoid drinking wine before writing recipes, even on Christmas eve ;)

Dec 25 2008 17:26

Just wondering how I could get the timezone setting of wordpress so I could check the date relative to where I am and not where the server is at. Thanks!

Dec 25 2008 21:02

And a Happy Chanukah to all!

Dec 26 2008 20:51

We should be thanking you for the delicious meals you share with us :p

And by the way, how can I add multiple statements, like for example, Christmas Day, I want this message and then on another date I want another message?

Dec 27 2008 22:45

php date() doesn’t take the server hour?

I think a better idea is to have a little JS hack to take computer’s time :)

just a small idea, because of the GMT time differences :) – you got the point I guess :) )

Dec 31 2008 07:35

Yeah, I’m using a JS hack on my blogs to take the computer’s current time, but this is obviously a lot simpler, and would take less time to do.

Jan 03 2009 12:41

So you agree with me :p

Best solution is JS related :)

Dec 01 2009 17:23

And, if you planned ahead, you could throw in multiple if statements and put in all the holidays… probably at that point, though should read them from a MySQL table as they could be easily edited, added to, etc..

If you wanted to get even more complicated, you could create a series of holiday-themed headers linked to the holiday record and display them on a particular date… a whole year of holiday wishes in one fell-swoop

Sounds like a plug-in opportunity.

Trackbacks:

Leave a Comment

* Name, Email, Comment are Required