Regarding to the performances, should I check if a post has a thumbnail before or after checking if is the front page (or single page, etc.)?

Neither, they are just as fast as each other, both are using information that has already been fetched in advance. This is micro-optimising. Functions such as is_front_page or is_singular etc etc are just looking up variables already set in the main query object. Likewise functions such as has_post_thumbnail etc are looking up data that has … Read more

Remove default Image Sizes

To unset all default image sizes in WordPress using PHP you can use this function: add_filter( ‘intermediate_image_sizes’, ‘remove_default_img_sizes’, 10, 1); function remove_default_img_sizes( $sizes ) { $targets = [‘thumbnail’, ‘medium’, ‘medium_large’, ‘large’, ‘1536×1536’, ‘2048×2048’]; foreach($sizes as $size_index=>$size) { if(in_array($size, $targets)) { unset($sizes[$size_index]); } } return $sizes; } Alternatively, you can also unset default images by going … Read more

image_size with respect to aspect ratios

Right before image subsizes are created, there’s a filter called intermediate_image_sizes_advanced that lets you modify the list of sizes. Here’s code that you could expand on — right now it just removes the thumbnail as a proof of concept: function remove_image_sizes_before_generation( $new_sizes, $image_meta, $attachment_id ) { $width = $image_meta[0]; $height = $image_meta[1]; // … Calculate aspect … Read more

How do you add a featured image to a page (not post)?

You can enable featured image for pages (and other post types) by using the line below. This goes in your functions.php file. add_theme_support( ‘post-thumbnails’, array( ‘post’, ‘page’ ) ); If you’re not comfortable with editing theme files then you should contact your theme developer. If featured images are not enabled by default in your theme … Read more

Get Post Thumbnail Outside of Loop

Off top of my head here’s two possible solution concepts. 1) Just run the custom loop (I meant to type, query) again and this time use it with only the_post_thumbnail. <?php if ($myposts->have_posts() ) : ?> <div class=”image-wrapper e-in”> <?php while ($myposts ->have_posts() ) : $myposts ->the_post(); ?> <div class=”image “> <!–Post Iamge Will Show … Read more