Conditional statements to find & use the day of the week in WordPress

[one_half padding=”0 25px 0 0″]We were working on a recent project where we had to figure out what day of the week it was and present something on the frontend of the website specifically for each day. The conditional script could be used to change any aspect of a website design based on the day of the week.

It is important to change the settings in WordPress under “Settings” > “General” and next to “Timezone” to be accurate to the timezone of your website. Once you do this, and use the code below, the script will accurately display or do whatever you echo in the php script. You can of course also use a php switch for this if you like.

Note about the timezone : we set the timezone directly in the script because working with server times and the WordPress timezone setting can be a little weird we’ve found, so it’s best to set the timezone directly.
[/one_half][one_half_last padding=”0 0px 0 0″]

date_default_timezone_set('America/New_York'); // Put your PHP supported timezone in place of America/New York
$script_tz = date_default_timezone_get();
// get current day:
$currentday = date('l');
if ($currentday == Monday){
echo '
Monday
'; } elseif ($currentday == Tuesday){ echo '
Tuesday
'; } elseif ($currentday == Wednesday){ echo '
Wednesday
'; } elseif ($currentday == Thursday){ echo '
Thursday
'; } elseif ($currentday == Friday){ echo '
Friday
'; } elseif ($currentday == Saturday){ echo '
Saturday
'; } elseif ($currentday == Sunday){ echo '
Sunday
'; } else{ //what, you were looking for other days? =/ }

[/one_half_last]

Latest from the Lab

What does a website cost in Fort Myers and Naples? Informational $2k to $4k, custom WordPress $4k to $8k, ecommerce $6k to $15k

How Much Does a Website Cost in Fort Myers and Naples?

Real website prices for Southwest Florida small businesses, from $2,000 informational sites to custom
EnterpriseHS.org shown on a desktop browser and a phone

Website Launch: Enterprise High School in Clearwater, FL

The new EnterpriseHS.org answers families’ first questions up front and turns enrolling into four
American Pool Water website shown on a laptop browser and a phone

Making a Splash: A New Brand & Website for American Pool Water

A new logo and website for American Pool Water, a pool water delivery company
blank

Alliant Association Management: New Logo, Brand Identity and Website

A new logo, brand identity and website for Alliant Association Management, an HOA and