- This topic has 8 replies, 3 voices, and was last updated 6 years, 1 month ago by Tom.
-
AuthorPosts
-
March 7, 2018 at 11:19 am #514138Dev
I am using “Page Header” and assigning “Global Locations” for different Page Headers. I understand that I can override the default page header for a given post type on the post edit page.
What I want to do, however, is to dynamically change the Post Header for a Published Post based on if the “Featured Image” has been set.
I may do this by writing a WP Cron function to look at all the published posts in the last 24 hours and change the “Page Header” if a featured image has been set.
How may I approach doing this? I know how I can write a function to check for a featured image, I can write a wp cron job. What I don’t know however is how I can change the “Page Header”.
Effectively the same option that is provided in the UI in “generate-meta-box-content” on post edit page, but do that dynamically.
March 7, 2018 at 3:57 pm #514272LeoStaffCustomer SupportHi there,
If I understand this correctly, all you have to do is to create a page header and turn on Add Background Image without actually uploading an image in that specific page header.
This will make it so that the page header will automatically grab the featured image you assigned for that post/page and use it as a background image.
Let me know if this helps.
March 7, 2018 at 5:55 pm #514310DevLeo/Tom,
Thanks for suggesting that alternate option. I have been aware of it, however, like mentioned in my previous email I wish to invoke the assignment of a GP “Page Header” to a post programmatically. This is because my page header for a post with a featured image will be different from the post without it.Essentially, all I am asking for is how do I invoke the function that can be used to change the page header associated with the post. The functionality found in the UI for “Edit a post” in the meta boxes below the post.
Under UI, this is found under generate_layout_options_meta_box -> #generate-layout-page-header -> Select box name “_generate-select-page-header”
March 7, 2018 at 8:50 pm #514361TomLead DeveloperLead DeveloperIn GPP 1.6 (available for testing: https://generatepress.com/gp-premium-1-6/), we introduced a new filter:
generate_page_header_id
This filter allows you to change the Page Header ID based on your select conditions.
So you can write your conditionals to select a certain post or set of posts, and change the ID to a specific Page Header.
Let me know if you need more info π
March 8, 2018 at 5:37 am #514605DevThanks Tom. I will give that a try.
March 8, 2018 at 10:17 am #514945TomLead DeveloperLead DeveloperNo problem π
March 25, 2018 at 7:29 am #529983DevIs this filter available now in 1.6?
Would you mind sharing an example of how to use it?
March 25, 2018 at 8:01 am #530084DevNever mind. I figured it out.
March 25, 2018 at 9:31 am #530167TomLead DeveloperLead DeveloperAwesome π
For others who are curious, this should do it:
add_filter( 'generate_page_header_id', function( $id ) { if ( is_page( 'about' ) ) { return 17686; // ID of the Page Header to use. } return $id; } );
-
AuthorPosts
- You must be logged in to reply to this topic.