Site logo

Archived topic

Block/Hook Element Display Rules - Dynamic Child Pages and Page Author Targeting

3 replies · Started by Sam on April 13, 2021

Viewing posts 1–4 of 4

I want to create visual block that can be hooked into multiple pages using the block element - my current wish is to hook a block on a page and all (future) child pages, without having to manually add hundreds of them each time (think: a block for a "section" of the site with relevant section-wide content).

If I use a hook element, I can include PHP to tailor the display of the element content based on arbitrary criteria, such as post author or parent page (get_post_ancestors), or inject other custom fields into the content.

However, it seems that if I use a block element, my options are more limited: I can get a better display of content and create it more visually with the block editor, but lose some of the selection criteria and dynamic content I can include with the hook element.

How could I achieve displaying a block element either by URL pattern filtering or other criteria such as post ancestors or post author? Are there any plans for custom display rules on all elements based on PHP filtering, or to add author/ancestor based targeting?

Hi there,

Elements do have a filter for the display rules eg.

generate_block_element_display

Here's one example of that:

https://generatepress.com/forums/topic/elements-block-hook-location-for-specific-url/#post-1669018

The logic behind the Display Rules is crazily complicated - so we're still looking at ways of expanding those for more advanced conditions.

You may also want to check out GPP 2.0 - which brings dynamic content:

https://generatepress.com/introducing-the-gp-theme-builder/

This brings some conditional controls to the content itself eg. if you include some post meta - it will only display if the content exists. Or you can set a GB Container block to display only if said meta exists.

Hi David,

Awesome - thanks. I'd just stumbled on the page in the documentation with the list of all filters, and was going through them to see if one was relevant - looks like conditionally hiding in the child theme is the way to go then for now.

Thanks!
Sam

In GPP 2.0 ( coming next week ) - we added this filter: generate_element_display

Which would apply to ALL elements - no need to determine if its a Block or a Hook - just target the Element ID.

Glad to be of help.

This archived topic is closed to new replies.