How to extract image width from add_image_size?

Generally speaking, there’s no need to do this. However, if it’s one added using add_image_size, it will be in the $_wp_additional_image_sizes global. global $_wp_additional_image_sizes; echo $_wp_additional_image_sizes[‘small’][‘width’];

Do I need to resize an image to fit the post?

You should use the built-in WordPress media manager to attach/insert images in posts. That way, if you define $content_width appropriately, WordPress will auto-resize large sized images to fit accordingly. Otherwise, you’ll have to rely on using CSS to set the max-width property for images within your content container (e.g. #content img{ max-width: 500px; height: auto; … Read more

HTML tags in WordPress image caption

I’m glad that better support should be added in version 3.4 but for now I’ve fixed the issue by changing the behaviour of image insertion so that it doesn’t use the shortcode. Here’s what I added to functions.php: add_filter( ‘disable_captions’, create_function(‘$a’, ‘return true;’) ); function image_send_to_editor_2($html, $id, $caption, $title, $align, $url, $size, $alt) { if … Read more

Gallery post images on homepage?

You could use this loop for fetching the images from current post. <?php $images = get_posts(array( ‘post_parent’ => get_the_ID(), ‘post_type’ => ‘attachment’, ‘posts_per_page’ => 5, ‘post_mime_type’ => ‘image’ )); if( $image ) { foreach($images as $image) : echo wp_get_attachment_link( $image->ID, ‘thumbnail-size’, true ); endforeach; } ?> reference: wp_get_attachment_link wp_get_attachment_image

Is there a way to delete images from WordPress media library programmatically?

This can be achieved with wp_delete_attachment( $attachment->ID ); Here’s an example to delete all attachments related to a post: // Delete Attachments from Post ID 25 $attachments = get_posts( array( ‘post_type’ => ‘attachment’, ‘posts_per_page’ => -1, ‘post_status’ => ‘any’, ‘post_parent’ => 25, ) ); foreach ( $attachments as $attachment ) { wp_delete_attachment( $attachment->ID ); }

Remove image classes from post thumbnail output

You might try something like this in your functions.php: //remove class from the_post_thumbnail function the_post_thumbnail_remove_class($output) { $output = preg_replace(‘/class=”.*?”https://wordpress.stackexchange.com/”, ”, $output); return $output; } add_filter(‘post_thumbnail_html’, ‘the_post_thumbnail_remove_class’);

add_image_size() to crop images into squares?

If you pass true for the last $crop argument then so called “hard” crop mode is used. This will make WP produce results at exact size specified, except few edge cases (if image uploaded is smaller than specified size for example). Note that original image is still retained as is. If you need to actually … Read more

Is it possible to pull and display a single landscape oriented image

Function to retrieve “landscape” oriented image function wpse_96012_landscape_image() { /* global post object holding info about the current post */ global $post; /* grab all images attached to the current post */ $attached_images = get_children( array( ‘post_parent’ => $post->ID, ‘post_type’ => ‘attachment’, ‘post_mime_type’ => ‘image’ ) ); /* set minimum ratio between width / height, … Read more