Show featured image option not in screen options

The “All Posts” page – /wp-admin/edit.php – does not show a featured image just by using WP Core. You have to add code to display featured images there. You may need to look back at your backups to see what code you were previously using to get the featured image to show up. It could … Read more

How can you limit srcset on a single type of page?

Here’s an example for filtering out sizes above set limit from the srcset attribute on certain post type. This works for featured image and images added to the post content with Gutenberg. (Tested on Twenty Twenty theme). function filter_wp_calculate_image_srcset( $sources, $size_array, $image_src, $image_meta, $attachment_id ) { global $post; if ( $post && ‘post’ === $post->post_type … Read more

How to extract image width from add_image_size?

Generally speaking, there’s no need to do this. However, if it’s one added using add_image_size, it will be in the $_wp_additional_image_sizes global. global $_wp_additional_image_sizes; echo $_wp_additional_image_sizes[‘small’][‘width’];

Get most recent media upload

I don’t think that you can use get_the_post_thumbnail function to get last uploaded media, but you can use get_post to get latest attachment and then wp_get_attachment_image to display images. $attachments = get_posts( array( ‘post_type’ => ‘attachment’, ‘posts_per_page’ => 1, ‘post_status’ => null, ‘post_mime_type’ => ‘image’ ) ); foreach ( $attachments as $attachment ) { echo … Read more

Do I need to resize an image to fit the post?

You should use the built-in WordPress media manager to attach/insert images in posts. That way, if you define $content_width appropriately, WordPress will auto-resize large sized images to fit accordingly. Otherwise, you’ll have to rely on using CSS to set the max-width property for images within your content container (e.g. #content img{ max-width: 500px; height: auto; … Read more