[Resolved] Featured Image Blog vs Single Post

Home Forums Support [Resolved] Featured Image Blog vs Single Post

Home Forums Support Featured Image Blog vs Single Post

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #415448
    Julien

    Hey Tom !

    This theme is such a joy to work with !
    I do face an issue with featured images.

    On the blog page I have set featured images to be cropped like this :
    Width : 1140
    Height : 570
    I did this setting in the GP Customize Options (Blog => Featured Images)

    It shows how I want it to be :
    http://www.nightlycrypto.com/

    The problem is with the single post, it retains the original aspect ratio :
    http://www.nightlycrypto.com/2017/11/03/li-europan-lingues-es-membres/

    For this I use, as recommended in another support ticket.

    add_action( 'generate_before_content', 'tu_add_featured_image' );
    function tu_add_featured_image() {
        if ( is_singular( 'post' ) && has_post_thumbnail() ) {
            the_post_thumbnail();
        }
    }

    I tried manually adding this size in the function, without luck :

    add_action( 'generate_before_content', 'tu_add_featured_image' );
    function tu_add_featured_image() {
        if ( is_singular( 'post' ) && has_post_thumbnail() ) {
            add_image_size('featured-single',1140,570,TRUE);
            the_post_thumbnail('featured-single');
        }
    }

    I have no plugins going on for now except your theme and GP Premium.

    Can you help me out ?

    Many thanks,
    Julien

    #415650
    Leo
    Staff
    Customer Support

    Hi there,

    Do you mind GPP 1.5 premium a shot? https://generatepress.com/forums/topic/gp-premium-1-5/

    It actually gives you separate re-sizing options for main blog page and single posts pages so no function needed.

    Otherwise try this: https://docs.generatepress.com/article/adjusting-the-featured-images/#changing-the-featured-image-sizes-using-a-filter

    Let me know ๐Ÿ™‚

    #415689
    Julien

    Hey Leo ! Thanks for the support.

    I installed GPP 1.5 (nice to see all those new features).

    Unfortunately, no luck with it.

    I set the sizes for both of featured images (blog and single). It doesn’t work, and I suspect it’s linked to the Page Headers tool from GPP I use. Using page headers I can only add featured images by using some code in functions.php.

    I don’t get why the_post_thumbnail(); generates something different on the front page, and on my single post page.

    You can see examples here :

    1. With a custom page header :
    http://www.nightlycrypto.com/2017/11/03/featured-image-test/

    2. Without a custom page header (two images, one from the functions.php , the second one from the settings) :
    http://www.nightlycrypto.com/2017/11/03/gravida-iaculis-pulvinar-natoque-ornare-nonummy-lacinia-diam/

    Edit :

    I also tried the code as a second solution without luck :

    add_filter( 'generate_blog_image_attributes','tu_variable_image_sizes' );
    function tu_variable_image_sizes( $atts )
    {
        // Set up our conditional
        if ( is_singular( 'post' ) && has_post_thumbnail() ) :
            $atts[ 'width' ] = 1140;
            $atts[ 'height' ] = 570;
            $atts[ 'crop' ] = true;
        endif;
    
        // Return our options
        return $atts;
    }
    #415927
    Tom
    Lead Developer
    Lead Developer

    If you’re going to add a custom image size, you need to hook it into the after_setup_theme hook:

    add_action( 'after_setup_theme', 'tu_add_image_sizes' );
    function tu_add_image_sizes() {
        add_image_size( 'featured-single', 1140, 570, TRUE );
    }

    Then try your code:

    add_action( 'generate_before_content', 'tu_add_featured_image' );
    function tu_add_featured_image() {
        if ( is_singular( 'post' ) && has_post_thumbnail() ) {
            the_post_thumbnail( 'featured-single' );
        }
    }

    You may need to regenerate your thumbnails with a plugin like this: https://en-ca.wordpress.org/plugins/regenerate-thumbnails/

    #415998
    Julien

    Perfecto ! It worked like a charm.

    Thanks Tom and Leo.

    #416159
    Tom
    Lead Developer
    Lead Developer

    You’re welcome ๐Ÿ™‚

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.