Adding Alt Attributes Automatically when Uploading Images to Media Library

A viable solution I found was adding the post title to images missing the ALT attribute. Add the following to your functions.php file: function add_alt_tags($content) { global $post; preg_match_all(‘/<img (.*?)\/>/’, $content, $images); if(!is_null($images)) { foreach($images[1] as $index => $value) { if(!preg_match(‘/alt=/’, $value)) { $new_img = str_replace(‘<img’, ‘<img alt=”‘.$post->post_title.'”‘, $images[0][$index]); $content = str_replace($images[0][$index], $new_img, $content); } … Read more

Function to get image from media library

Here you go: function get_media_all_wpa14177(){ $args = array( ‘post_type’ => ‘attachment’, ‘post_mime_type’ =>’image’, ‘post_status’ => ‘inherit’, ‘posts_per_page’ => -1, ); $query_images = new WP_Query( $args ); $images = array(); foreach ( $query_images->posts as $image) { $images[]= $image->guid; } return $images; } Usage: $Images = get_media_all_wpa14177();

resize from small images to large

Found a solution here that is working: http://www.binarynote.com/how-to-perfectly-upscale-image-in-wordpress.html function binary_thumbnail_upscale( $default, $orig_w, $orig_h, $new_w, $new_h, $crop ) { if ( !$crop ) return null; $aspect_ratio = $orig_w / $orig_h; $size_ratio = max($new_w / $orig_w, $new_h / $orig_h); $crop_w = round($new_w / $size_ratio); $crop_h = round($new_h / $size_ratio); $s_x = floor( ($orig_w – $crop_w) / 2 … Read more