Convert all images to PNG on file upload

(Updated answer) The sight() function not only uploads the image, but also creates an attachment (i.e. a post of the attachment type); hence, I updated the code — it’s now in a function named attachment_to_png, and that it uses the get_attached_file() to get the image file attached to that attachment, and the update_attached_file() to update … Read more

IMG src weird behaviour inside a single post loop

the_post_thumbnail function display the post thumbnail i.e. <img> tag. You don’t need to use <img> tag when using this function. Try this code: <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <article class=”post”> <h2 class=”postTitle”><?PHP the_title(); ?></h2> <?php the_post_thumbnail( ‘predefImageSize’, [‘class’ => ‘singleMainImg’, ‘title’ => ‘Feature image’] ); ?> <p class=”postinfo”>Created on <?php the_time(‘F … Read more

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