When does WP resize an image file

WordPress resizes the image when you upload it. By default it provides 4 sizes of your image (providing your image is bigger than the ‘large’ size). the_post_thumbnail(‘thumbnail’); // Thumbnail (default 150px x 150px max) the_post_thumbnail(‘medium’); // Medium resolution (default 300px x 300px max) the_post_thumbnail(‘large’); // Large resolution (default 640px x 640px max) the_post_thumbnail(‘full’); // Original … Read more

Random background image showing on website per click/load

If you want to use add_image_size, your images must be uploaded as WordPress attachments, and not only be present inside a specific folder. So first of all register your custom size: add_action( ‘after_setup_theme’, ‘gmrb_background_image_size’ ); function gmrb_background_image_size() { // using WP 3.9 crop position // see https://codex.wordpress.org/Function_Reference/add_image_size#Crop_Mode add_image_size( ‘gmrb_background’, 1500, 1500, array( ‘center’, ‘center’) ); … Read more

Resize images in batch

Ankit you can re-size images by using this script via terminal: <?php ini_set(‘max_execution_time’, 0); set_time_limit(0); require_once(‘./wp-load.php’); require_once( ‘./wp-admin/includes/admin.php’ ); for($i=0;$i<=500;$i++){ $attachments =& get_children(array( ‘post_type’ => ‘attachment’, ‘post_mime_type’ => ‘image’, ‘numberposts’ => 50, ‘paged’ => $i, ‘post_status’ => null, ‘post_parent’ => null ), ARRAY_A); foreach ( $attachments as $attachment ) { $image = get_post($attachment[‘ID’]); $original_size_path = … Read more

Get all image IDs from the Media Library

From my understanding I can’t get the image IDs directly from wordpress. I have to first get their URLs and then extract their IDs. If there is a more efficient way to do this please let me know. I’m not sure I follow you there, but did you try this: $ids = get_posts( array( ‘post_type’ … Read more

Display image for first sticky post only

Try this : <ul> <?php $args = array( ‘category_name’ => ‘महाराष्ट्र’, ‘post__in’ => get_option( ‘sticky_posts’ ), ‘showposts’ => ‘6’, ); $the_query = new WP_Query( $args ); $count = 1; while ($the_query -> have_posts()) : $the_query -> the_post(); ?> <li> <?php if ( 1 == $count ): ?> <div class=”thumbnail_class”><a title=”<?php the_title(); ?>” href=”https://wordpress.stackexchange.com/questions/150086/<?php the_permalink() ?>” … Read more

Why can’t I display attachment_image_src with Custom Size?

With wp_get_attachment_image_src you get a array with values corresponding to the (0) url, (1) width, (2) height, and (3) scale of an image attachment (from the wordpress doc). you code can be: if($imageid){ $image_attributes = wp_get_attachment_image_src( $imageid, ‘custom-size-01’, false); echo “<img src=\””; echo $image_attributes[0]; echo “\” width=\”100%\” >”; }

Google Page Speed Insights – Optimize Images

First, don’t let Google Insights drive you to chase an ROI that might not be there. Maybe for 1M of image data improvement, it is worth looking into – but after awhile that tool will have you minifying 1K css files to save 100 bytes. Second, regarding images – don’t just blindly reduce (‘compress’…really a … Read more