- This topic has 23 replies, 4 voices, and was last updated 4 years, 11 months ago by
Tom.
-
AuthorPosts
-
April 20, 2021 at 6:23 pm #1742440
Elvin
StaffCustomer SupportA part of this code is broken.
add_action( 'init', function() { add_image_size( 'hero-image', 500, 300, true ); add_image_size( 'eventhero-image', 700, 400, ); } );In
add_image_size( 'eventhero-image', 700, 400, );the400,has a,but you didn’t specify true or false for the cropping parameter.If you don’t want to specify, remove the
,. So you either do:
add_image_size( 'eventhero-image', 700, 400 );
OR
add_image_size( 'eventhero-image', 700, 400, true );So it will look like this:
add_action( 'init', function() { add_image_size( 'hero-image', 500, 300, true ); add_image_size( 'eventhero-image', 700, 400, true ); } );As for the PHP snippet for hero thumbnail:
this should work:
add_filter( 'generate_hero_thumbnail_id_size', function($size) { // Set defaults size if conditions not met $size = 'full'; // Check if post is your_first_post_type if ( is_singular( 'events' ) ) { $size = 'eventhero-image'; } // Else check if is your_other_post_type elseif ( is_singular( 'profiles' ) ) { $size = 'hero-image'; } // Return the thumbnail size return $size; });I only added the CPT slugs and the image handle names.
April 20, 2021 at 10:46 pm #1742593qpaq
Ah I see, I corrected the size code. But problem persists; the resized thumbnails are not displayed on posts. This snippet causes the post to display the original uploaded sizes of the images.
// Add new image sizes add_action( 'init', function() { add_image_size( 'hero-image', 500, 300, true ); add_image_size( 'eventhero-image', 700, 400 ); } ); add_filter( 'generate_hero_thumbnail_id_size', function($size) { // Set defaults size if conditions not met $size = 'full'; // Check if post is your_first_post_type if ( is_singular( 'events' ) ) { $size = 'eventhero-image'; } // Else check if is your_other_post_type elseif ( is_singular( 'profiles' ) ) { $size = 'hero-image'; } // Return the thumbnail size return $size; });April 20, 2021 at 11:27 pm #1742636Elvin
StaffCustomer SupportAh I see, I corrected the size code. But problem persists; the resized thumbnails are not displayed on posts. This snippet causes the post to display the original uploaded sizes of the images.
I believe this isn’t retroactive. If you’ve added the image size AFTER adding the image, you’ll have to make WordPress generate these added image sizes.
Can you try regenerating the image sizes to be sure?
https://wordpress.org/plugins/regenerate-thumbnails/April 21, 2021 at 1:55 pm #1743750qpaq
Yes, I’ve regenerated the thumbnails with that plugin. I have both
hero-image: 500×300 pixels (cropped to fit)andeventhero-image: 700×400 pixels (proportionally resized to fit inside dimensions)for each image. Yet the neither theeventsnor theprofilesCPTs retrieve them.April 21, 2021 at 6:00 pm #1743885Elvin
StaffCustomer SupportThat’s quite strange.
Can you link us to a sample post with images for
eventsandprofilesCPT?Can you let us temporarily access the backend as well to check the Header Element? So we could do a closer inspection.
You can use the private information text field for the details. Let us know.
April 21, 2021 at 11:31 pm #1744089qpaq
Sure, I’ll write it down. Let me know what you’ve changed so I can record it.
April 22, 2021 at 5:05 pm #1745326Elvin
StaffCustomer SupportAh I think I see the problem here.
the code was written for a custom post type. Your posts don’t seem to be custom post types but rather, custom taxonomy terms under “Content type”.
You may have to use
is_tax()rather thanis_singular(). Do you know the slug of “Content Type”? Let us know.April 22, 2021 at 11:28 pm #1745528qpaq
Hi Elvin,
Sorry my mistake. Not familiar so much with the terminology.
The Content Type taxonomy is created by PODS.
content_typeis the slug I think you’re asking for.
The two Content Types I would like to differentiate by the size of featured images areeventsandprofilesI changed to snippet as you suggested, re-generated the thumbnails and purged the cache but the result is the same, problem not resolved.
// Add new image sizes add_action( 'init', function() { add_image_size( 'hero-image', 500, 300, true ); add_image_size( 'eventhero-image', 700, 400 ); } ); add_filter( 'generate_hero_thumbnail_id_size', function($size) { // Set defaults size if conditions not met $size = 'full'; // Check if post is your_first_post_type if ( is_tax ( 'events' ) ) { $size = 'eventhero-image'; } // Else check if is your_other_post_type elseif ( is_tax ( 'profiles' ) ) { $size = 'hero-image'; } // Return the thumbnail size return $size; });April 23, 2021 at 9:19 am #1746254Tom
Lead DeveloperLead DeveloperHi there,
You may need to ask Pods what condition you need to use. Looking at the body classes of that post,
is_tax()won’t work, either. There doesn’t seem to be any other clues in the HTML as to which condition to use, unfortunately. -
AuthorPosts
- You must be logged in to reply to this topic.