- This topic has 5 replies, 2 voices, and was last updated 5 years, 6 months ago by Tom.
-
AuthorPosts
-
October 17, 2018 at 8:21 am #703331Lars Steen
Hello GP.
It seems that i can’t change header pr. page in a easy way.
Why is it that it’s not possible to choose what header to display on each page, and then make an override of the elements header display rules?
It’s seems like it gives a lot of confusion, if you have 3 types of headers for pages for example.
What do you recommend I do about it?
And i’m not sure how to explain this simple to end admin user.What approach do you recommend here?
Best regards. Lars.
October 17, 2018 at 1:27 pm #703595TomLead DeveloperLead DeveloperHi there,
Are you wanting a select dropdown while creating pages to select a Header, kind of like the old Page Header module?
This is something we wanted to move away from in Elements. It adds an additional layer of complexity and can be confusing when Display Rules aren’t working (because a metabox is set instead).
The direction of WordPress (Gutenberg, no metaboxes) was also a factor in our decision.
Instead, it’s actually really easy to choose pages directly within the Header Element. This way all of your conditions are within one area.
October 17, 2018 at 1:42 pm #703604Lars SteenHello Tom
Thanks for the fast response.
“Are you wanting a select dropdown while creating pages to select a Header, kind of like the old Page Header module?”
Yes. I think this is needed. I will build this myself then.“The direction of WordPress (Gutenberg, no metaboxes) was also a factor in our decision”
I think it’s too early to remove it totally still.Maybe I Just don’t get it. But would the meta boxes not just live inside a Gutenberg “block” if needed? If so, isn’t this just another way to override like the old page header module?
Feel free to correct me if i’m wrong.
Best regards. Lars.
October 17, 2018 at 1:48 pm #703609TomLead DeveloperLead DeveloperThe way Page Headers worked per page was something I didn’t really like before. However, I’m always open to feedback when it comes to this kind of stuff.
Let me know if you need any help building a solution – the code telling the Header to apply shouldn’t be too hard with the
generate_header_element_display
filter.October 18, 2018 at 12:50 am #703840Lars SteenHello Tom.
Thanks for wanting to help.
I choose to do it via AFC.
Here is my code, to get somebody started if they want the same.
In ACF create and assign the post_object field to the page, make it return an ID
Code goes in fx. functions.php
// filter for a specific field based on it's name the ACF field is of the type post_object add_filter('acf/fields/post_object/query/name=choose_header', 'm_query_headers_post_object_query', 10,3); function m_query_headers_post_object_query( $args, $field, $post_id ) { // Only show GPP headers $args['meta_query'] = array( array( 'key' => '_generate_element_type', 'value' => 'header', 'compare' => 'EXISTS' ), ); // return return $args; } add_filter( 'generate_header_element_display', 'm_control_show_header',10, 2 ); function m_control_show_header ($display, $element_id) { global $post; // Try to get the header id $id_of_header_to_display = get_field('choose_header',$post->ID); // Check if it's assigned if (is_int($id_of_header_to_display)) { if ($element_id == $id_of_header_to_display) { return true; } } else { // Or do normal GPP return $display; } }
It’s working for my needs for now, NB. Did not test fully yet.
Best regards. Lars.
October 18, 2018 at 9:53 am #704336TomLead DeveloperLead DeveloperGreat work – exactly how I would have done it 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.