Loop through child images of a parent for a Nivo Slider

To get attached (i.e. child) images of a post, try using get_children(). e.g.: <?php $child_image_args = array( ‘post_mime_type’ => ‘image’, ‘post_parent’ => $postID, ‘post_type’ => ‘attachment’ ); $child_images = get_children( $child_image_args ); ?> Which returns an associative array of child images. Then, just loop through them, e.g. using wp_get_attachment_image(), to output. e.g.: <div id=”nivoslider”> <?php … Read more

Open the attachment details modal

Unfortunately the logic of the attachment details isn’t made to be used standalone – it requires the grid that opens it. You can however use the get_media_item( attachment_id ) method to receive the HTML of the form for modifying images: https://developer.wordpress.org/reference/functions/get_media_item/

Adding custom image size to the media image editor

As far as i know it is possible with image_size_names_choose hook (see https://codex.wordpress.org/Plugin_API/Filter_Reference/image_size_names_choose). Example: // add your custom size function my_setup_image_sizes() { add_image_size( ‘wide-image’, 900, 0); } add_action( ‘after_setup_theme’, ‘my_setup_image_sizes’ ); // add custom size to editor image size options function my_editor_image_sizes( $sizes ) { $sizes = array_merge( $sizes, array( ‘wide-image’ => __( ‘Image 900px … Read more

Is it possible to prevent users from uploading small images?

Here you go: if(!current_user_can(‘delete_others_posts’)){ /*Handling wp media uloads*/ add_filter(‘wp_handle_upload_prefilter’,’lets_handle_img_width’); function lets_handle_img_width($file) { $img = getimagesize($file[‘tmp_name’]); $width = $img[0]; if ($width < 350){ $file[‘error’] = “Image is small too small. Get something of width more than 350px.”; } return $file; } } Check official documentation about wp_handle_upload_prefilter.

How to change _wp_attachment_metadata specific value in SQL?

You could do this via PHP instead of SQL, just get the existing metadata and change what you need to, it will handling the serializing for you: $newwidth=”250″; // or whatever it is $attachments = get_posts(array(‘post_type’=>’attachment’); foreach ($attachments as $attachment) { $id = $attachment->ID; $metadata = wp_get_attachment_metadata($id); $metadata[‘width’] = $newwidth; wp_update_attachment_metadata($id,$metadata); } But really, you … Read more

Can images be automatically compressed?

Use http://wordpress.org/extend/plugins/auto-image-resizer/ Add this to your functions.php: function prune_image_sizes($sizes) { // You can add other size like that for remove those sizes // unset($sizes[‘medium’]); unset($sizes[‘large’]); return $sizes; } add_filter(‘intermediate_image_sizes_advanced’, ‘prune_image_sizes’); Set your large image option to 800px in media options panel. So what did you do? System will not create large size of image but … Read more

Define size for `get_post_gallery_images`, they seem to have been resized to 150×150

If you want get_post_gallery_images to give you full size images, you can use the following: // Use full size gallery images for the next gallery shortcode: add_filter( ‘shortcode_atts_gallery’, ‘wpse_141896_shortcode_atts_gallery’ ); // Your code: $gallery = get_post_gallery_images( $post ); foreach ($gallery as $img) { ?> <li><img src=”https://wordpress.stackexchange.com/questions/141896/<?php echo $img; ?>” /></li> <?php } where /** * … Read more

No srcset for hard-cropped thumbnails

To show a srcset, there must be multiple image sizes of the same aspect ratio. When you set your thumbnail to hard crop without creating any other image sizes you are ensuring that there won’t be a srcset. You might find my answer here helpful. Briefly, in your case, adding this line: add_image_size ( ‘double-size’, … Read more