Generate image size, based on the image-orientation

Here is my working solution. The code is documented, so it should be clear what each function does. I pretty much use the wp_generate_attachment_metadata filter to create the needed images after the image has been uploaded. The generated images are listed in the metadata too, like any other intermediate image size. That way you can … Read more

Did I do it right? Deleting images after deleting product. Woocommerce

Looking at @obmerks answer on https://stackoverflow.com/questions/12997698/delete-images-after-post you can simplify it with this: foreach ( $productIds as $productId ) { $child_atts = $wpdb->get_col(“SELECT ID FROM {$wpdb->posts} WHERE post_parent = $productId AND post_type=”attachment””); foreach ( $child_atts as $id ) wp_delete_attachment($id,true); } Note: as per documentation https://codex.wordpress.org/Function_Reference/wp_delete_attachment set the second parameter to true to force delete the attachment, … Read more

Get total number of pixels, size in megapixels and aspect ratio based on image width and height?

Sure – php can definitely handle simple math like this. All you’d have to do is reference the numbers coming back from the wp_get_attachment_image_src call: <?php if ( has_post_thumbnail()) { $full_image_info = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), ‘full’); $img_h = $full_image_info[1]; $img_w = $full_image_info[2]; $total_pixels = $img_w * $img_h ; $megapixels = round($total_pixels) /* see http://at2.php.net/manual/en/function.round.php — they … Read more

alt, title tags not showing

It actually depends upon how the image is shown in the template. If it is shown using a function like the_post_thumbnail() which returns complete html string to show image with alt then there should be no problem but if image is shown by only fetching URL then it depends how it is displayed . For … Read more

Wrap all post images inside a div element

Try using PHP’s regular expression find/replace function—preg_replace()—in a filter on the the_content hook. function breezer_addDivToImage( $content ) { // A regular expression of what to look for. $pattern = ‘/(<img([^>]*)>)/i’; // What to replace it with. $1 refers to the content in the first ‘capture group’, in parentheses above $replacement=”<div class=”myphoto”>$1</div>”; // run preg_replace() on … Read more