Support » Theme: Koji » Featured images and sizes when moving from Fukasawa to Koji

  • Resolved Chris Hardie

    (@chrishardie)


    Following up on this thread https://wordpress.org/support/topic/featured-image-on-posts-is-stretched/ I’m another user working on moving from Fukasawa to Koji. I’m hoping to do it without regenerating image sizes for all of the 2,500+ images in my media library, so I’m testing out this function in my child theme:

    
    function jchphotos_theme_setup() {
    	remove_image_size( 'koji_preview_image_high_resolution' );
    	remove_image_size( 'koji_preview_image_low_resolution' );
    	set_post_thumbnail_size( 88, 88, true );
    	add_image_size( 'post_image', 973, 9999 );
    	add_image_size( 'post-thumb', 508, 9999 );
    	add_filter( 'post_thumbnail_size', function() { return 'post-thumb'; } );
    }
    
    add_action( 'after_setup_theme', 'jchphotos_theme_setup', 11 );
    

    I *believe* this gets me back to the same image size list as was used in Fukasawa and fixes the display of images on single post view pages, without otherwise compromising Kuji’s functionality. I’m a little unsure of this for the high/low res preview images, but so far haven’t noticed an issue.

    I realize this is a little hacky and may introduce future issues. But I thought I’d share this here (1) in case it’s useful to others and (2) to see if the theme author has any comments/thoughts on this approach. Thanks!

    • This topic was modified 5 months, 3 weeks ago by Chris Hardie.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Theme Author Anders Norén

    (@anlino)

    Hi @chrishardie,

    That approach should work, although you would also need to plug the koji_get_preview_image_size() function, and return “post-thumb” in the function in your child theme. Otherwise, archive pages will try to display the image sizes you remove (either “koji_preview_image_high_resolution” or “koji_preview_image_low_resolution”, depending on the Customizer setting), and since they are removed, the full size of the images would be loaded instead.

    — Anders

    Thanks for the fast response! Since preview.php calls the_post_thumbnail() and I’m filtering post_thumbnail_size I think that would take care of the preview image case too…although arguably one would want different sizes for archive views and single page views. So now I’m using:

    
    function jchphotos_post_thumbnail_size() {
    	if ( is_single() ) {
    		return 'post_image';
    	} else {
    		return 'post-thumb';
    	}
    }
    
    function jchphotos_theme_setup() {
    	remove_image_size( 'koji_preview_image_high_resolution' );
    	remove_image_size( 'koji_preview_image_low_resolution' );
    	set_post_thumbnail_size( 88, 88, true );
    	add_image_size( 'post_image', 973, 9999 );
    	add_image_size( 'post-thumb', 508, 9999 );
    	add_filter( 'post_thumbnail_size', 'jchphotos_post_thumbnail_size' );
    }
    
    add_action( 'after_setup_theme', 'jchphotos_theme_setup', 11 );
    
Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.