Question about add_image_size()

First, let’s check the behavior of cropping. According to code reference: If false (default), images will be scaled, not cropped. If an array in the form of array( x_crop_position, y_crop_position ): x_crop_position accepts left, center, or right. y_crop_position accepts top, center, or bottom. Images will be cropped to the specified dimensions within the defined crop … Read more

A mystery 300px image size

Updated Answer After doing more testing, the 300px size only gets generated when I have the official WooCommerce Brands plugin activated. So 300px is the default WooCommerce image size when the standard sizes go undefined. See wc_get_image_size() in \includes\wc-core-functions.php. It seems that at some point WC must have filled in the blank of a missing … Read more

Escape post image attachments added to template

Running the output through escaping function should be just fine. You can either use wp_kses_post(), which by default allows the same html attributes that you would use in the post content (see in codex): echo wp_kses_post( wp_get_attachment_image( $image_id ) ); or if you want to be more precise and strict, you can pass an array … Read more

Display the featured image from the last post

This should work. I’ve modified your $args a little and surrounded your echoed code within the while(have_posts()) : the_post(); loop, then added the the_post_thumbnail() function and, finally, the wp_query_reset(); at the bottom: <?php $limit = 999; $counter = 0; $categories = get_categories(); foreach ( $categories as $category ): if ( $counter < $limit ) { … Read more

The the post id from image id

The featured image is stored as post meta with the key _thumbnail_id, so you could use a meta query to get posts with a specific thumbnail: $posts = new WP_Query( array( ‘meta_query’ => array( array( ‘key’ => ‘_thumbnail_id’, ‘value’ => $attachment_id, ), ), ) ); Where $attachment_id is the ID of the image.

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