Site logo

Archived topic

Post/Page Feature image in Logo Location

13 replies · Started by Kristian on June 23, 2021

Viewing posts 1–14 of 14

Is there a way where I can have the feature image of the post/page load in the location where the Logo image is (above the navigation bar)? In the past, I needed to add some CSS code in my child theme (I just purchased GeneratePress yesterday).

Let me know if you need more info.

Thanks!

Hi Ying!

Yes. In the private, I have provided several pages of my site in the old theme so that you can see what I want to do. If you notice with each page, the top center image is the feature image.

I only have it for the pages (the posts have the default Logo), but it would also be cool to do that for the posts if possible.

I am currently staging the website with the GeneratePress theme and Generate Blocks. I can show an image of that as well, but it's pretty much just every page and post with the default logo image.

You can try creating a block element:
https://docs.generatepress.com/article/block-element-overview/

Add a dynamic image block into the block element:
https://docs.generatepress.com/article/dynamic-blocks/

Set Hook as element type, set before_navigationas hook name.

Set post > all posts as location.

Please be noted, in order to use the dynamic block, you'll need to install and activate Generateblocks plugin.
https://wordpress.org/plugins/generateblocks/

Lastly, you can disable the default featured images in single posts:
https://docs.generatepress.com/article/adjusting-the-featured-images/

Let me know if you need further assistance :)

Thanks! I believe I did everything right. I am including the link to the uploaded image in private.

As you can see, the featured image is now above navigation bar but the Logo is still there.

I would like to...

1.) ...center the Featured image
2.) ...link the featured image to the homepage (so that a visitor can click it to return there)
3.) ...if possible, replace the Logo placement with the feature image.

Thanks!

Hi Kristian,

If all you really need to do is to change the logo with the featured image, we can do a filter for that.

We can use:

add_filter( 'generate_logo', function( $logo ) {
    $id = get_post_thumbnail_id();

    if ( $id ) {
        $size = 'full';
        $img_src = wp_get_attachment_image_url( $id, $size );
        // $img_srcset = wp_get_attachment_image_srcset( $id, $size );
        return $img_src;
    }

    return $logo; 
 } );

But since you want to change it's layout, I don't think this the best way to do it.

If I may suggest, if you simply want a centered featured image on the header, don't upload a logo and hook in the featured image instead.

If you can provide us a mockup image of how you want things to be laid out, we can provide a more specified answer towards that layout goal. :)

Hi Elvin,

What do you mean when you say I want to change the layout? Is it because I want it centered?

I did remove the logo and now have the only featured image in the header but I can't center it (I've included link of the screenshot in private).

Also, in private, I've included two links of how my live site currently deals with the featured image so that you can see.

The image is usually of a medium size and you can click on it to return to the home page.

Thanks for your help.

Hi Kristian,

We can help you to center the image, but we have to see the actual site to provide the exact code, otherwise, we can only provide code by guessing, it's not efficient at all.

So can you link us to the staging page?

Let me know :)

Hi Ying,

Sure thing! I'll put the link in the Private section along with the username/password to access the site.

I can see the image is there, could you wrap a GB container outside the dynamic image block in the block element?

In that case, you can directly center the image within the GB container without using any CSS.

Let me know :)

That worked - I got it centered! Thanks!

With the container, there's an option to link to a Custom field via the Custom Field name

Is there a field name I can enter to link back to the home page?

Thanks! It does work with posts, but not with pages - but I'm fine with that.

I've added a HOME button on the Navigation bar, so I'm pretty happy where things are now.

Thanks again for all your help and patience. I've learned a lot along this journey.

That's great :)

Glad to hear that!

This archived topic is closed to new replies.