No comments after business hours

Security bars over a handwritten sign that says WE ARE NOW CLOSED.

TBH, managing your blog’s comments can sometimes feel like a second job. You want engagement, you love the discussion, but it can also be kind of a drag. For me, especially as I’ve started regularly posting here again, I wanted to maintain some of my off-hours peace without keeping comments off entirely.

My solution? Setting up business hours — an idea I feel like I stole from Jenn Schiffer, who was maybe doing business hours for some other project of hers — for when folks can leave new comments. Kind of like a brick-and-mortar shop. And the best part? I did it with Nick Diego’s fantastic Block Visibility plugin for WordPress.

The idea was a simple one: I wanted the comment submission form on my posts to only be visible and submittable between 9:00 AM and 5:00 PM, Monday – Friday, Pacific Time.

Any comments left during those hours, or any that were already on my site before I flipped this switch, still get displayed perfectly fine. It’s not about silencing discussion — but rather managing when the door is open for people to stop by and talk.

As I mentioned, the Block Visibility plugin is a lifesaver for this kind of control over all sorts of site components. It lets you set conditions for when any block (or group of blocks) should appear. In this scenario, I’m using the Twenty Twenty-Five theme — though this should work with any block theme — and the process is surprisingly straightforward.

Once you’ve installed and activated Block Visibility, here’s what you need to do:

  1. Edit your Single Post template: Head into your Site Editor (Appearance → Editor) and navigate to your site’s Single Post template.
  2. Select the appropriate block: Find the block responsible for rendering the actual form where visitors type their comments. In my case, and in many themes, this is the Post Comments Form block.
  3. Open Block Visibility settings: With the block selected, look for the Block Visibility settings in the block inspector panel on the right. You might need to click the lil three-dot menu on the block’s toolbar to find Visibility — or it might be a dedicated panel.
  4. Set the Schedule: This is where the magic happens!
    • Click to add a Date & Time visibility control.
    • You’ll want to set it to Show the block if the schedule applies.
    • For the days, uncheck Saturday and Sunday, leaving Monday, Tuesday, Wednesday, Thursday, and Friday selected.
    • Under During this time interval, set FROM to 09:00 AM and “TO” to 05:00 PM.

And that’s pretty much it. Now, your site’s comment form will only appear during your designated business hours.

I also like to add a little notice above the comment area (using a Paragraph block) to let folks know about the commenting hours.

Something like “The ability to comment on posts is available only during business hours (Monday – Friday, 9am – 5pm UTC).” works just fine.

It all sounds pretty simple, right? Well, there’s a little wrinkle that I ran into. You might too, depending on your hosting setup.

Caching is great for site speed, but it can also mean that your comment form might stay open after 5pm or closed after 9am because the cached version of a page is still being served.

My site is hosted with SpinupWP, which has its own caching layer, on top of object caching. To make sure the changes kick in as promptly as possible, I had to get a touch more technical and set up some server side cron jobs.

For those comfortable with the command line, or for those whose hosts provide cron access, here’s the fix. I set up two cron jobs: one to run just after comments close, and one to run just after they open.

Here’s some genericized versions of what I use in cron. You’ll need to adjust the paths and specific caching commands for your own hosting environment:

# Clear WordPress object cache and [$host] site cache at 9:01 AM, Monday-Friday
1 9 * * 1-5  cd /path/to/your/wordpress/install && wp cache flush && wp cache purge-site

# Clear WordPress object cache and [$host] site cache at 5:01 PM, Monday-Friday
1 17 * * 1-5 cd /path/to/your/wordpress/install && wp cache flush && wp cache purge-site

What’s happening here?

  • 1 9 * * 1-5: This is the cron schedule. It means run this command at minute 1, past hour 9 (9:01 AM), Monday through Friday.
  • The second schedule is the same but timed for 17:01 (5:01 PM), also Monday through Friday.
  • cd /path/to/your/wordpress/install: This makes sure the command gets run where your WordPress files live.
  • wp cache flush: This is a WP-CLI command to flush the WordPress object cache.
  • wp cache purge-site: This is a placeholder for your hosting provider’s specific WP-CLI command to purge their site-level cache.

By running these a minute after the scheduled change to block visibility, we ensure that any cached pages are cleared, and the correct state of the comment form (visible or hidden) is served to visitors.

It might seem like there’s a few hoops to jump through, especially if caching is a factor for you, but I swear that it’s totally worth it. My site (and its visitors) now respect my office hours, past comments still get displayed, and I’m not tied down by stupid moderation duties.

Comments

The ability to comment on posts is available only during business hours, for thirty days from the entry’s publication date.

Business hours: Monday – Friday, 9am – 5pm Pacific Time