Articles of wp get attachment image

Get the URL, width and height of an image where the width and height are a specified minimum

Is it possible to get the URL, height and width of an image where the height and width are as a minimum the size I specify? wp_get_attachment_image_src() almost does this, but not quite, grabbing instead the image where either one of the height or width is as a minimum the size I specify. Example For […]

Display featured image file size, extension, filename, type, orientation?

How to display some information of featured image in post. I need to display: 1. a. Image file size (in kb or MB) b. Image type (.jpg,.gif…), c. Bare image name, with and/or without image extension (some-image-file-name.jpg). Also, if it possible it would be nice to show this too: d. orientation of image (landscape, portrait) […]

wp_get_attachment_image_src returns image on main domain, false on subdomain

I’ve got a multisite install in development where both the subdomains and the main site use the exact same page templates for showing data. However, when I try to get a profile image (added ID in wp_usermeta), I get false on the subdomains, but the actual image data returned on the main domain. I came […]

Making images from single.php pointing to an attachment .php template

I am trying to make the inserted images from a post (single.php) to point to (single-attachement.php) an attachment page. So far I checked a post here on stackexchange and added this code on the top, before the header of single.php, just that it’s showing me a link to the last image on the page, instead […]

wp_get_attachment_image_src always returns false

I’m using wp_get_attachment_image_src to retrieve image URL. Codex is simple for this function and starting from an ID on my database I used wp_get_attachment_image_src in this way: $image_url = wp_get_attachment_image_src(2447); echo $image_url[0]; where 2447 is an ID of an attachment in my wp_posts db table (already checked). Everything seems correct, but trying to execute the […]

Why this thumbnail hard crop code does not work?

I am trying to show thumbnail image as an attachment in the feed. So I use following code. function add_images_to_rss($var) { global $post; if(has_post_thumbnail($post->ID)) { $tid = get_post_thumbnail_id( $post->ID); //$thumb = wp_get_attachment_image_src($tid, ‘large’); $thumb = wp_get_attachment_image_src($tid, ‘100×100’); $thumb_meta = wp_get_attachment_metadata($tid); $up = wp_upload_dir(); print ‘<enclosure type=”‘.get_post_mime_type($tid).'” length=”‘.filesize($up[‘basedir’].’/’.$thumb_meta[‘file’]).'” url=”‘.$thumb[0].'” />’; } } add_action(‘rss2_item’,’add_images_to_rss’); But it shows […]

Display all attached image of every post of custom post type and link to original post

I’ve written a loop that displays all the images that are attached to every single post of a specific post type. The post type is called “atls_events” and I’m outputting an image size called “video-thumb” for each image attached to each post. I have all of that working. You can see the code here: <?php […]

How do I get the URL of a specific size featured image?

I am using <?php wp_get_attachment_thumb_url( $attachment_id ); ?> to get the url of a thumbnail for a post in WordPress. However I would like to retrieve the URL of a specific size image. So for example when displaying the post thunmbnail normally you can specify a size, like: <?php the_post_thumbnail( $size, $attr ); ?>. Is […]

How do I intercept and modify the functionality of wp_get_attachment_image()?

I have a site I’m building in wordpress that has ~80GB of high resolution images, and it’s exceeding my managed host’s storage space. My plan is to move all the images to S3, but I noticed that wp_get_attachment_image() automatically prefixes the src with /wp-content/uploads instead of respecting the path stored in the database. Is there […]

Get ID for previous/next image link

For grabbing previous or next image link on attachment page we can use this https://codex.wordpress.org/Function_Reference/previous_image_link How do we get ID for that attachment? Because I would like to get its alt title by using this echo get_post_meta(get_the_ID(), ‘_wp_attachment_image_alt’, true); and put it below image, with maybe also a few more stuff.