How can I reduce home page and post page thumbnail image when same thumbnail both side
How can I reduce home page and post page thumbnail image when same thumbnail both side
I want to change home page and blog post page thumbnail size. I noticed thumbnail size generate through same class'large' on both pages.
html code is:
home page code
<img width="750" height="422" src="https://amazquiz.com/wp-content/uploads/2023/11/amazon-fz-points-weekly-qu…" class="attachment-large size-large wp-post-image" alt="amazon-fz-points-weekly-quiz-answer" itemprop="image" decoding="async" srcset="https://amazquiz.com/wp-content/uploads/2023/11/amazon-fz-points-weekly-qu…" sizes="(max-width: 750px) 100vw, 750px">
Blog post code
<img width="750" height="422" src="https://amazquiz.com/wp-content/uploads/2023/11/amazon-fz-points-weekly-quiz-answer.jpg" class="attachment-large size-large wp-post-image" alt="amazon-fz-points-weekly-quiz-answer">
I change tried to change it from funtion.php but no change. Let us know php code editing.
What you need to do:
Define new image sizes: Add code to your functions.php file to define the new image sizes.
Use Conditional Tags: To define different sizes on different pages
Example Implementation:
function my_custom_image_sizes() {
add_image_size('homepage-thumb', 800, 450, true);
add_image_size('postpage-thumb', 600, 300, true);
}
add_action('after_setup_theme', 'my_custom_image_sizes');
function my_custom_thumbnails($html, $post_id, $post_image_id, $size, $attr) {
if(is_home() && $size == 'large') {
$size = 'homepage-thumb';
} elseif(is_single() && $size == 'large') {
$size = 'postpage-thumb';
}
$image = wp_get_attachment_image_src($post_image_id, $size);
if ($image) {
$html = '<img src="' . $image[0] . '" width="' . $image[1] . '" height="' . $image[2] . '" alt="' . get_the_title($post_id) . '">';
}
return $html;
}
add_filter('post_thumbnail_html', 'my_custom_thumbnails', 10, 5);
January 7, 2024
Turbo Multi-language Translator
Make the better internet purchasing globaly
Turbosify SEO Speed Booster
5.0 (7)•Free plan available
Get better conversions by improving store loading speed
Installed
Turbo Multi-language Chat - AI Customer service in one hand
January 7, 2024