[Resolved] updating the header in the posts page

Home Forums Support updating the header in the posts page

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #1024626
    eric

    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

    };

    #1024645
    Leo
    Staff
    Customer Support

    Hi 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-2

    Let me know 🙂

    #1024716
    eric

    I 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?

    #1024760
    David
    Staff
    Customer Support

    Hi 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.

    #1025377
    eric

    Thanks 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.

    #1025791
    Tom
    Lead Developer
    Lead Developer

    Hi 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 🙂

    #1027206
    eric

    That works! Thanks very much! I really appreciate it!

    #1027255
    Tom
    Lead Developer
    Lead Developer
Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.