Two Ways to Add Custom Messages to WordPress, Part I

(TRANSCRIPT)
One of the reasons blogs and websites are such popular forms of media is because of how interactive they can be. Today we’re going to look at two ways to add custom messages to your website or blog, which are small ways to add a little more interactivity- and add more value- to them.

We’re doing this in WordPress, which- as I’m sure you must know by now- is my preferred method of online publishing.

First, I’m going to show you how to display a custom message on a specific date. This can be very useful- for example, you can set a special Christmas greeting to show your visitors on Christmas Day- AND since you code this in ahead of time, you can do it as early as a month before or more.

To do this, all it takes is a little snippet of PHP code. PHP code is what powers WordPress. This is the snippet you need:

<?php
if ((date(‘m’) == 12) && (date(‘d’) == 25)) { ?>

<p>Hooray! It’s Christmas Day!</p>

<?php } ?>

Let me break that down a bit for you. It’s really quite simple if you look at it. The instructions here are IF the month- signified by “m”- is 12 (December) AND the day- signified by “d”- is 25, THEN you display whatever is between the two PHP tags.

Let’s try this on one of my blogs, and set it to today, so that we can see the message right away.

I want to add this to the very top of my main page. So I’ll open up the index.php file in my WordPress theme, and paste it right here:

<?php
if ((date(‘m’) == 3) && (date(‘d’) == 29)) { ?>

<p>It’s March 29th. Have you had a cupcake today?</p>

<?php } ?>

Let’s have a look at it. And there it is!

I want to add a few styles to it, so it stands out. It’s better to do this is your CSS style document, but I’ll add it inline just for this tutorial. Now let’s save it, and reload my blog to see it with styles on.

Obviously, you can use this technique to display things other than a custom message on a specific date- some special code or markup, or a photograph.

In Part II, we’ll be looking at how to display a customized message to your returning visitors.