---
title: How to Show and Hide Gutenberg Blocks in Context
date: 2019-08-17T07:32:46+00:00
modified: 2019-08-17T07:58:45+00:00
image:: https://kaspars.net/wp-content/uploads/2019/08/block-context-settings.png
permalink: https://kaspars.net/blog/show-hide-wordpress-blocks
post_type: post
author:
  name: Kaspars
  avatar: https://reverse.kaspars.net/gravatar/avatar/92bfcd3a8c3a21a033a6484d32c25a40b113ec6891f674336081513d5c98ef76?s=96&d=mm&r=g
post_tag:
  - Gutenberg
  - Plugin
  - WordPress Blocks
category:
  - WordPress
---

# How to Show and Hide Gutenberg Blocks in Context

I created the [Block Context plugin](https://blockcontext.com) to change the visibility of WordPress blocks based on various rules and conditions. It uses the `<a href="https://github.com/preseto/block-context/blob/289fe69f7c6d26d646e958617a13f6ad7fb5eea0/php/BlockContextPlugin.php#L53">render_block</a>`[ filter](https://github.com/preseto/block-context/blob/289fe69f7c6d26d646e958617a13f6ad7fb5eea0/php/BlockContextPlugin.php#L53) to [hide a block based on the rules](https://github.com/preseto/block-context/blob/289fe69f7c6d26d646e958617a13f6ad7fb5eea0/php/BlockContextPlugin.php#L86-L94) selected in the block settings:

![Block Context settings for each Gutenberg block](https://kaspars.net/wp-content/uploads/2019/08/block-context-settings.png?strip=all&quality=90&resize=1024,663)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](https://twitter.com/intent/tweet?screen_name=konstruktors) 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!