Media_handle_upload with custom upload folder?

If I’m not mistaken, then it should be possible. You want to use media_handle_upload(), which calls wp_handle_upload() to handle the file upload. wp_handle_upload() on itself won’t be helpful, especially because it is pretty much just a wrapper for _wp_handle_upload(). It’s not the end yet, because inside _wp_handle_upload() the function wp_upload_dir() is called, where we find … Read more

Display image file size in media library

In your theme’s functions.php add the following code to get the file size for all of your items in the Media library: add_filter( ‘manage_upload_columns’, ‘wpse_237131_add_column_file_size’ ); add_action( ‘manage_media_custom_column’, ‘wpse_237131_column_file_size’, 10, 2 ); function wpse_237131_add_column_file_size( $columns ) { // Create the column $columns[‘filesize’] = ‘File Size’; return $columns; } function wpse_237131_column_file_size( $column_name, $media_item ) { // … Read more

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();