Site logo

Archived topic

Hide or show blocks when logged in or logged out?

3 replies · Started by Martin on October 20, 2022

Viewing posts 1–4 of 4

Not sure if this is possible.
Is it possible to set a GenerateBlocks block to only be visible to logged in users / logged out users?

Thanks.

Martin

Hi Martin,

It's possible, but you'll need custom code for that.

If you're adding the Blocks through a Block Element, it's possible through the Display rules.

What do you mean "through a block element"?
I'm adding GenerateBlock containers with grids inside and then my content inside there.

If you're using a Block Element, in the Display Rules, you can set it up so the it appears only to logged in or logged out users. Example: https://share.getcloudapp.com/4gueGnKE

So, you can create a Block Element and inject the Block you want appearing or disappearing depending if a user is logged in or not.

If you're placing it in a specific location in your content which isn't available through the current hooks, you'll need to create a portable hook. For this, see my response here: https://generatepress.com/forums/topic/hooks-related-question/#post-2170598

This archived topic is closed to new replies.