Tagged: featured image, single post
-
AuthorPosts
-
February 16, 2021 at 2:57 pm #1281353
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 :)
February 18, 2021 at 12:19 pm #1281968Hey 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,
IsmaelFebruary 20, 2021 at 3:06 pm #1282480Hi 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.February 23, 2021 at 12:54 pm #1283063Hi,
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,
IsmaelMarch 13, 2021 at 7:37 pm #1288047Can you let me know what the first conditional is?
(I’m not too familiar with PHP)Thanks again.
March 15, 2021 at 7:41 am #1288200Hi 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 -
AuthorPosts
- You must be logged in to reply to this topic.
