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

Share on facebook
Facebook
Share on twitter
Twitter

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.

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? =/ }

Let's Talk
We can't wait to hear about your project.
  • required
  • required
  • required
  • required
    *Sorry, "Johnny Flyaway" recently retired. We hope an email response or phone call will suffice.
    Spam isn't fun. We promise to only send you emails with helpful marketing & design tips, and life changing information. Ok, maybe the latter is a bit of an exaggeration, but it's possible!
  • This field is for validation purposes and should be left unchanged.
Web & Logo Design Blog

© 2021 Brian Joseph Studios LLC. All rights reserved

Facebook | Twitter | Instagram | Web Design Naples | Web Design Fort Myers | Logo Design Fort Myers | Logo Design Naples | LinkedIn | Thumbtack | Brian Joseph Studios is featured on Florida Web Design

Fort Myers - (239) 989 3306 | Naples - (239) 280-1294

Google Business Listing - Brian Joseph Studios - Naples Web Design Company