- This topic has 7 replies, 4 voices, and was last updated 4 years, 5 months ago by Tom.
-
AuthorPosts
-
October 2, 2019 at 12:57 pm #1024626eric
Hi there,
I’ve updated the header.php file to create my own banner throughout the site I’m working on. It works as intended on all pages except one.
One the posts page (assigned on the settings, reading page), it pulls up the image and title of the first POST, instead of the pages title and featured image. Is there an easy way to change this? Thanks in advance.
global $post;
if (!is_page_template( ‘SDhome.php’ ) ) {
if ( has_post_thumbnail() ) {
echo ‘‘;
$featured_image = get_the_post_thumbnail_url($post, ‘hero-image’ );
$title = get_the_title();
echo ‘‘;
echo $title;
echo ‘‘;
echo ‘<div class = “hero” style= ” background-image: url( ‘;
echo $featured_image;
echo ‘)”>’;
echo ‘‘;
echo ‘‘;
echo ‘‘;
}
} else { // home page};
October 2, 2019 at 1:10 pm #1024645LeoStaffCustomer SupportHi there,
Have you tried using our header element add-on to create a page hero?
https://docs.generatepress.com/article/header-element-overview/I believe that’s what you are after.
You can see some examples here:
https://docs.generatepress.com/article/page-hero-examples/#example-2Let me know π
October 2, 2019 at 2:53 pm #1024716ericI like this approach but here are the issues I’m experiencing with it.
1) is it possible to control the size of the featured image that comes up. Ideally, I would like to use a customized size.
2) This functionality doesn’t address my initial problem of the blog posts featured image. It pulls up the “fall back” image but not the one specified on the page. Is that possible to change?
3) Is there an easy way to change the title from “blog” to something else?
October 2, 2019 at 4:35 pm #1024760DavidStaffCustomer SupportHi there,
1. the Header Element sets the featured Image as a CSS Background Image. So to change its size you need to adjust the top / bottom padding to increase the elements height.
2 and 3. The Blog page is not a standard page for one it doesn’t use the_title function and WP ignores meta boxes including featured image. So for the blog you would need to create a separate header element and set the title and background image you need.
October 3, 2019 at 8:13 am #1025377ericThanks for the clarification. On my first question, I meant the file size, not the image size. I have a number of customized media sizes (e.g. hero, thumbnail, etc.) and it would be helpful to pull up the appropriate size. The header function seems to only pull up up the image’s original size? Thank you in advance.
October 3, 2019 at 7:35 pm #1025791TomLead DeveloperLead DeveloperHi there,
You could try something like this:
add_filter( 'generate_page_hero_background_image_url', function( $image_url, $options ) { if ( is_singular() && has_post_thumbnail() ) { $image_url = get_the_post_thumbnail_url( get_the_ID(), 'large' ); } return $image_url; }, 10, 2 );
Just change
full
to whatever size you want to use πOctober 5, 2019 at 2:06 pm #1027206ericThat works! Thanks very much! I really appreciate it!
October 5, 2019 at 4:14 pm #1027255TomLead DeveloperLead DeveloperYou’re welcome π
-
AuthorPosts
- You must be logged in to reply to this topic.