The new Gutenberg editor will soon be merged in the WordPress core. And with the new editor, you might want to show/hide Gutenberg blocks to logged in users only or maybe want to know how you can restrict visibility for non-logged in users.
The show/hide Gutenberg blocks to logged in users comes in handy if you’re running a WordPress membership or an ecommerce website. Here, at DevotePress, we will be guiding you on how you can show/hide Gutenberg blocks to logged in users in WordPress using a plugin. Let’s get started.
Show/Hide Gutenberg Blocks to Logged in Users in WordPress
For this tutorial, we will be using Block Options plugin to manage the visibility of blocks. It is a WordPress Gutenberg Management tool that is completely free of cost.
After you’ve installed and activated the Bock Options plugin, visit Settings > Block Options to check out the settings that come along with the plugin.
Now, to show/hide Gutenberg blocks to logged in users, you can head over to your existing posts. Or, you can also create a new one as well. We will be editing our existing article for the tutorial.
On the right sidebar of the Gutenberg editor, you will now see a new option called Block Options.
Under that option, you can manage your blocks better. You can restrict visibilities and add custom display logic using WordPress conditional tags.
On the Device Visibility option, you can select the devices (Desktop, Tablet or Mobile) and show/hide specific blocks on your selected devices.
Likewise, on the User Login State option, select the visibility option that suits best for you. You can restrict blocks visibility for logged-in or logged-out users. There are two options to choose from: Show blocks only for Logged-in Users or Show blocks only for Logged-out users.
Save your changes and you’re done! That’s all you need to do. Since we’ve selected the ‘Show only for Logged-in Users’ option, the block you’ve edited will only be shown to the logged in users. Visit your website to see the plugin in action. You can repeat the steps if you have any other blocks to restrict on user states.
If you have anything to add, share or ask, feel free to use the comments section.