How to Show and Hide Gutenberg Blocks in Context

I created the Block Context plugin to change the visibility of WordPress blocks based on various rules and conditions. It uses the render_block filter to hide a block based on the rules selected in the block settings:

Block Context settings for each Gutenberg block
Block Context settings for each Gutenberg block.

Visibility Rules

What are the conditions and rules that would be actually useful to you? Please leave a comment below or send me a message on Twitter with your suggestions.

Here is what I have come up with so far:

  • Users and user roles — targer logged-in or logged-out users, specific user roles and capabilities.
  • Time and date period — select a date range when the block is visible.
  • Device type — mobile, desktop, tablet, etc. This should be done in JS/CSS to ensure it works with any kind of caching.
  • Referrals — show blocks to users coming from search engines, social networks, specific URLs, etc.

What else? Can’t wait to hear your suggestions!

Use Contact Form 7 to collect business leads and enquiries? I created Storage for Contact Form 7 plugin which stores them safely in WordPress database.

Get it Now →

Leave a Reply