I have searched high and low for this. How do I change my homepage based on the time of day? To be absolutely explicit, I want:

  1. Between 8am and 7pm - Homepage 1 (node/4)
  2. Between 7pm and 8am - Homepage 2 (node/5)

So I want to design two completely different homepages and then they change based on time of day.

I tried some code but it doesn't seem to do the job:

$current_front = variable_get('site_frontpage');

if($current_front== 'node/4'){

Note: I am not a code whizz so wouldn't know where to start with hooks and I'm a million years away from creating my own modules.


Consider using the Rules module to set the appropriate node as your frontpage.

Based on the sample in the question, I'm assuming that node/4 is what the value is of site_frontpage. Here is the actual rule to be created that could work in your case:

  1. Create a new rule
  2. Event = Content is viewed
  3. Condition: data comparison -> node:nid equals 4
  4. Add an extra condition to check if current time is between 7pm and 8am.
  5. Action: page redirect to node/5

For anybody not familiar (enough/yet) with Rules, checkout the 32 (!!!) great (+ free) video tutorials Learn the Rules framework. Possibly also the similar set of 8 video tutorials about the Flag module, often considered as a natural complement to the Rules module. Maybe also review the set of 30 video tutorials about the Views module ... Familiarity with only those 3 modules (Views, Rules and Flag) can get you pretty far in mostly any Drupal site (as a site builder).

  • Not sure I have the skills for that, but thanks. I did find this which seems to work as a selection rule in a panel:code $now = time(); $day = date("D", $now); return $day == "Tue”; codeI just need this to be between 8am-7pm now, if anyone knows how I can do that, I'd be grateful. Thanks. – Rich Stevens May 5 '15 at 8:14
  • Finally worked it out; added this to my panel selection rule: code$now = time(); $day = date("G", $now); return $day < "15";code For anyone as useless as me, this means I am checking if the time is before 15.00 hours, if it is then this rule passes so my panel shows. Thanks. – Rich Stevens May 5 '15 at 8:34

I would suggest a custom module with a couple of cron hooks (in one hook_cron function).

  • Set one cron hook (A) to change the front page to node/4.
  • Set the other cron hook (B) to change the front page to node/5.
  • Install Ultimate Cron, and use the Crontab scheduler.
  • Set hook A to * 8 * * *
  • Set hook B to * 19 * * *

Of course, that will only work based on your server clock, and won't change based on the user's time zone. If you want that it'll be more tricky.

  • Unfortunately I am not a code whizz so wouldn't know where to start with these hooks. Looks like I'll have to pay someone. Thanks for your answer in any case, might help someone more technically gifted! – Rich Stevens May 5 '15 at 2:54
  • You don't have to be whiz, Drupal and PHP are pretty easy to learn. Paying someone is an option, but so is learning how to make custom modules =) – Darvanen May 5 '15 at 3:44
  • I don't know what this means 'Set one cron hook (A) to change the front page to node/4.' I'm a million years away from creating my own modules. – Rich Stevens May 5 '15 at 5:33
  • Fair enough, it's good to know your limitations. – Darvanen May 5 '15 at 14:42

Have a look at the Theme Key module. Some more details about it, from its project page:

ThemeKey allows you to define simple or sophisticated theme-switching rules which allow automatic selection of a theme depending on current path, taxonomy terms, language, node-type, and many, many other properties. It can also be easily extended to support additional properties exposed by other modules. In combination with Drupal's theme inheritance you can easily achieve features like:

  • individually-styled channels
  • a front-page / "splash" screen
  • a date/time-selected Christmas theme
  • mobile themes for different auto-detected mobile devices
  • special themes for "limited" or "old" browsers
  • content, user, or role -specific themes
  • indicating your environment (production, staging, testing, sandbox, … )
  • testing your redesign safely on a live server

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.