Home › Forums › Support › Block/Hook Element Display Rules – Dynamic Child Pages and Page Author Targeting
- This topic has 3 replies, 2 voices, and was last updated 5 years, 1 month ago by
David.
-
AuthorPosts
-
April 13, 2021 at 11:21 pm #1733499
Sam
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?
April 14, 2021 at 4:27 am #1733747David
StaffCustomer SupportHi there,
Elements do have a filter for the display rules eg.
generate_block_element_displayHere’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.
April 14, 2021 at 4:41 am #1733785Sam
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!
SamApril 14, 2021 at 5:33 am #1733841David
StaffCustomer SupportIn GPP 2.0 ( coming next week ) – we added this filter:
generate_element_displayWhich 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.
-
AuthorPosts
- You must be logged in to reply to this topic.