Site logo

Archived topic

Using feature image on post hero

9 replies · Started by Tan on May 18, 2020

Viewing posts 1–10 of 10

Thank you David. It worked well. :)
I want specific size of feature image. How can I customize it?
And I want to show: "avatar author name | Updated date | Social share" under post title. Could you help me?

1. This line of the code:

$img_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'large', false );

You can replace large with any of the media thumbnail sizes you have.

This function allows you to add your own size if you require:

https://developer.wordpress.org/reference/functions/add_image_size/

2. A few steps are required for that layout:

This hero example shows how to add the Avatar | author | post date :

https://docs.generatepress.com/article/page-hero-examples/#example-2

To make the date show Updated requires this PHP Snippet:

https://docs.generatepress.com/article/show-the-updated-post-date/#show-the-“updated”-post-date-in-header-element

The Social Share icons you will require a plugin that provides a short code option ( most of em do )

I'm not familiar with the code :(. I want to show w=720px, h=auto. Could you help me with the code?
Thank you so much!

This article explains:

https://docs.generatepress.com/article/adding-image-sizes/

So you could add this:

add_action( 'init', function() {
    add_image_size( 'hero', 720 ); // 720px wide - auto height
} );

Then you can change this line in the shortcode to:

$img_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'hero', false );

It did not change the size of feature image. Could you check again?

Yes. It worked. I missed it! Thank you so much David! :)

You're welcome - looks great :)

This archived topic is closed to new replies.