Australia's Leading Digital Marketing Experts. T. 1300 235 433  |  Aggreagtion Enquires Welcome

Display a Different Image Each Day with Shortcode

This snipped will display a different image for each day of the week. As pointless as it is, it was requested way back in the Internoetics days. Create an image as monday.jpg, tuesday.jpg, and so on.

1
<?php 
2
/*
3
 Display a Different Image Each Day of the Week with Shortcode
4
 http://www.beliefmedia.com/code/wp-snippets/day-image
5
*/
6
 
7
function beliefmedia_day_image($images = 'images/dir') {
8
 $today = strtolower(date('l'));
9
 return (file_exists($images . '/' . $today . '.jpg')) ? '<img loading="lazy" width="50" height="50" src="' . $images . '/' . $today . '.jpg" border="0">' : 'No image was found for ' . $today;
10
}
11
add_shortcode('dayimage', 'beliefmedia_day_image');
12
 
13
/* Usage */
14
echo beliefmedia_day_image();

There's also a PHP function.

If you wanted to expand upon the code above, you could create all sorts of image combination effects.

1
$today = date('l'); // Day of week
2
$month = date('m'); // Month
3
$dweek = date('j'); // Day of the month without leading zeros - use "d" for a leading zero.

View the PHP manual for ideas on date usage.

Like this article?

Share on facebook
Share on Facebook
Share on twitter
Share on Twitter
Share on linkedin
Share on Linkdin
Share on pinterest
Share on Pinterest

Leave a comment