- This topic has 6 replies, 3 voices, and was last updated 1 month, 1 week ago by
David.
-
AuthorPosts
-
July 4, 2022 at 9:22 pm #2273299
Lox
Hello,
Basically, I need a page header for first level pages (does not have a parent), and another for children pages (has parent). But I see other use cases.
Is it possible to implement it with hooks ?
Regards.
July 4, 2022 at 9:43 pm #2273305Fernando Customer Support
Hi Lox,
Yes, it’s possible.
A specific filter for Hook Elements you may use is
generate_hook_element_display
.Reference: https://docs.generatepress.com/article/generate_hook_element_display/
So for instance, here’s a PHP snippet you may try:
add_filter( 'generate_hook_element_display', function( $display, $element_id ) { if ( 396602 === $element_id && is_page() ) { if( ! empty ( get_ancestors ( get_the_ID(), 'page' ) ) ) { //display if child $display = true; } else { $display = false; } } else if ( 706 === $element_id && is_page() ) { if( empty ( get_ancestors ( get_the_ID(), 'page' ) ) ) { //display if parent $display = true; } else { $display = false; } } return $display; }, 10, 2 );
Kindly replace
396602
with the Hook Element ID meant for the child, and706
for the parent pages.This only works for pages.
You would need to alter it for posts.
If you’re planning to use a Block Element instead for instance, just replace
generate_hook_element_display
withgenerate_block_element_display
.Hope this clarifies!
July 5, 2022 at 2:10 am #2273473Lox
Hard coding element ID is not really recommended …
July 5, 2022 at 5:29 am #2273614Lox
Could you please look for a way to programmatically add custom conditions in the metabox select ? I would be then up to the developer to use a hook to add its own conditions and another to check for them.
July 5, 2022 at 6:28 am #2273662David
StaffCustomer SupportHi there,
its not possible at this time, we are reviewing the display conditions functions for a future update.
For now – you would need to use the method that Fernando provided.Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/July 6, 2022 at 2:26 pm #2275370Lox
Hi,
I had a look. Adding a filter on the output of the
get_conditions()
(GeneratePress_Conditions
class) and another filtering the output ofshow_data()
method would do it.Regards.
July 7, 2022 at 3:27 am #2275853David
StaffCustomer SupportThanks for sharing that.
As i said we are reviewing the display conditions, we’re most likely to rebuild the current system so more complex conditions can be built within the UI. And with that we would include additional filters.Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/ -
AuthorPosts
- You must be logged in to reply to this topic.