- This topic has 9 replies, 4 voices, and was last updated 3 years, 4 months ago by
David.
-
AuthorPosts
-
April 13, 2019 at 9:05 am #868033
Melissa
I need to use a different for the featured image used in blog grids and the hero image on the blog post page. I can create a “hero image” ACF, but how could I use that as an option in my header Element background?
Thanks!
GP Premium 1.7.8April 13, 2019 at 4:24 pm #868185Tom
Lead DeveloperLead DeveloperHi there,
You can do something like this:
add_filter( 'generate_page_hero_background_image_url', function( $url ) { $background_image = get_post_meta( get_the_ID(), 'your_custom_field', true ); if ( $background_image ) { $url = $background_image; } return $url; } );
Just updated
your_custom_field
with the name of your custom field.Let me know 🙂
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentApril 14, 2019 at 9:28 am #868683Melissa
Should that give me the option in the drop-down menu on the edit header element page?
I added your filter with “Code Snippets” and can’t see any obvious effect. Was that the wrong place to add it?
April 14, 2019 at 2:15 pm #868846Tom
Lead DeveloperLead DeveloperNo, that should automatically use a different background image URL if it’s set as a custom field.
For example, if you have a Header applied to the “About” page, and the About page has a custom field with a URL in it, it would use that URL.
Let me know if that’s not what you were after 🙂
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentApril 14, 2019 at 4:25 pm #868908Melissa
Ok, I’ve got it working nicely now. The problem seems to be that I was using the custom field type “image” not URL.
Thanks so much!
April 14, 2019 at 8:26 pm #868988Tom
Lead DeveloperLead DeveloperYou’re welcome 🙂
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentNovember 22, 2019 at 3:40 am #1072146Rafał
Neat! Works for Elements’ Header.
Tom, can you give us a solution for.inside-article
(or any other container addressed by a class or id), please?November 22, 2019 at 6:49 am #1072448David
StaffCustomer SupportHi there,
something like this hooked into the
WP_head
:<?php $background_image = get_post_meta( get_the_ID(), 'your_custom_field', true ); if ( $background_image && is_single() ) { echo '<style> .inside-article { background-image: url("' . $background_image . '"); }'; } ?>
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/November 23, 2019 at 1:30 am #1073459Rafał
Thank you, David!!
I’ve used Elements’ Hook, chosen Display Rules, and to push it to thewp_head
needed to cut off the check ifis_single()
.
Closing tag</style>
was missed.
This works for me:<?php $background_image = get_post_meta( get_the_ID(), 'my_custom_field', true ); if ( $background_image ) { echo ' <style id="my-id" type="text/css"> .inside-article { background-image: url("' . $background_image . '"); } </style> '; } ?>
November 24, 2019 at 11:24 am #1075091David
StaffCustomer SupportOoops – thanks for updating an glad you got it resolved.
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.