Tagged: featured image, single post
Hi there,
I was hoping you could help with changing the featured image size on specific pages?
I tried this code that I found in another form post but it changes the featured image size across the whole site (even the admin area) and I want to do it only on single posts and also event posts. So that the image isn’t cropped.
add_filter( 'post_thumbnail_size', 'ebwp_single_event_post_thumbnail_size');
function ebwp_single_event_post_thumbnail_size($size) {
if( !is_singular('tribe_events') ) {
return;
}
if( ! has_post_thumbnail() ) {
return;
}
$size = 'large'; // Change to your desired image size.
return $size;
}
Thanks :)
Hey Orla,
Thank you for the inquiry.
The following condition can be adjusted to include the default post type.
if( !is_singular('tribe_events') ) {
return;
}
Replace it with:
if( !is_singular('tribe_events') || !is_singular('posts') ) {
return;
}
Let us know how it goes.
Best regards,
Ismael
Hi Isamel,
It does work but it also changes the featured image across the whole site like the previous code. In the admin area as well as thumbnails. Is there something else I could try?
Thanks.
Hi,
Sorry about that. Make sure to check that we are not on the admin page.
Please put this line before the first conditional.
if(is_admin()) return;
Best regards,
Ismael
Can you let me know what the first conditional is?
(I’m not too familiar with PHP)
Thanks again.
Hi Orla,
The code above just check if you are in the backend, if you are then it exits the function and if you aren’t then it continues to execute the code after it.
You can refer on the codex: https://developer.wordpress.org/reference/functions/is_admin/
Best regards,
Nikko