[Resolved] Change single page featured image

Home Forums Support [Resolved] Change single page featured image

Home Forums Support Change single page featured image

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1066741
    Mathieu

    Hi Tom,

    I am using add_image_size() to create a custom size that won’t waste bandwith/time for anybody.

    How can I hook into the code of the featured image (in the single page) so that the get_the_post_thumbnail() function uses my custom size?

    Or maybe there’s a feature somewhere that I am not seeing.

    Best regards,

    #1066748
    Leo
    Staff
    Customer Support
    #1066775
    Mathieu

    Well I was really looking into the hook. On the homepage, I do it easily a piece of code Tom gave me :

    add_filter('generate_featured_image_output', function () {
        $isHot = false;
        if (isHot(get_the_id())) {
            $isHot = '<span class="hotpost"></span><span class="hottexte">En vedette!</span>';
        }
        return sprintf( // WPCS: XSS ok.
            '<div class="post-image">
                %1$s
                <a href="%2$s">
                    %3$s
                </a>
            </div>',
            $isHot,
            esc_url(get_permalink()),
            get_the_post_thumbnail(
                get_the_ID(),
                apply_filters('generate_page_header_default_size', '<strong>liste</strong>'),
                array(
                    'itemprop' => 'image',
                )
            )
    
        );
    });

    But I guess that *could* do the same and be much cleaner.

    However, I have a few issue with using that built-in feature.

    1) I have no “image_processing_queue” cron events.

    2) When I am looking at the lists of available thumbnail I have inside the theme, I have nothing matching what I put in Β« Customize / Layout / Blog / Featured Image / Posts Β»

    So either I have something broken or it won’t play well with the image optimization tools I use.

    #1066928
    Tom
    Lead Developer
    Lead Developer

    You should just be able to do this:

    add_filter( 'generate_page_header_default_size', function( $size ) {
        if ( is_page() ) {
            $size = 'your-custom-size';
        }
    
        return $size;
    } );

    I’m not a fan of the current image resizer, either. I have a better idea I’ll be implementing in 2020 πŸ™‚

    #1067621
    Mathieu

    Ahhh thank you very much Tom. I am not sure why it didn’t work yesterday as I was testing something similar.

    Oh well, thanks again and have a nice day πŸ™‚

    #1067889
    Tom
    Lead Developer
    Lead Developer

    You’re welcome! You too πŸ™‚

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