Create a Link to Larger Image from within list of smaller images

Just use wp_get_attachment_image_src 2 times, to retrieve the 2 sizes: function display_images_in_list($size=”thumbnail”, $fullsize=”full”) { //.. previous function code is good … foreach($images as $image) { $th = wp_get_attachment_image_src($image->ID, $size); $full = wp_get_attachment_image_src($image->ID, $fullsize ); printf( ‘<a href=”https://wordpress.stackexchange.com/questions/114265/%s”><img src=”https://wordpress.stackexchange.com/questions/114265/%s” width=”%d” height=”%d” alt=”https://wordpress.stackexchange.com/questions/114265/%s” /></a>’, $full[0], $th[0], $th[1], $th[2], esc_attr( $image->post_title ) ); } } } the use … Read more

Always generate thumbnail after sideloading image

You’ll have to use wp_generate_attachment_metadata and wp_update_attachment_metadata to do this. // sideload it into wordpress (generates various sizes) $thumbid = media_handle_sideload( $file_array, $post->ID ); if ( is_wp_error($thumbid) ) { // deal with error here } // If this function is undefined in the environment where it is to be used, // such as within a … Read more

Retreive tags from attached post for media on page

‘attachment’, ‘posts_per_page’ => -1, ‘post_status’ => ‘any’, ‘post_parent’ => null, ‘tax_query’ => array( array( ‘taxonomy’ => ‘post_tag’, ‘field’ => ‘slug’, ‘terms’ => ‘logo’ ) ) ); $images = get_posts( $args ); if ( $images ) { foreach ( $images as $image ) { // Get the parent post ID $parent_id = $image->post_parent; // Get the … Read more

How to change default image rename?

I think you can only access $file and do something like below. add_filter(‘wp_handle_upload_prefilter’, ‘custom_upload_filter’ ); function custom_upload_filter( $file ){ $file[‘name’] = ‘wordpress-is-awesome-‘ . $file[‘name’]; return $file; } Also have a look how WP does it at wp-includes/file.php

How to add a credit line to a photo caption

I tried to do this once and almost got almost. Here’s what I did learn. Depending on your needs, this solution may be workable. You can append content to media when it’s inserted into the editor using the get_image_tag filter: /** * Filter to get caption and append image information to it. * * @return … Read more

Retrieving Image Storage path

Images (and all other attachments) are associated with a post in the posts table. The attachment source URL is saved in the guid column. That’s not a good choice, because sooner or later GUIDs won’t follow the URL scheme anymore, so don’t query that field directly.