Get Image Description

function wp_get_attachment( $attachment_id ) { $attachment = get_post( $attachment_id ); return array( ‘alt’ => get_post_meta( $attachment->ID, ‘_wp_attachment_image_alt’, true ), ‘caption’ => $attachment->post_excerpt, ‘description’ => $attachment->post_content, ‘href’ => get_permalink( $attachment->ID ), ‘src’ => $attachment->guid, ‘title’ => $attachment->post_title ); } Source As sporkme explains later in the thread, this is dumped into your functions.php and can then … Read more

remove or update add_image_size

The add_image_size( $name, $width, $height, $crop ) function is graceful enough to handle multiple calls using the same $name. It simply overwrites the existing value: $_wp_additional_image_sizes[$name] = array( ‘width’ => absint( $width ), ‘height’ => absint( $height ), ‘crop’ => (bool) $crop ); So that means that all you need to do to override the … Read more

Prevent WordPress from generating medium_large 768px size of image uploads?

To remove the medium_large image size you can try to remove it with the intermediate_image_sizes filter: add_filter( ‘intermediate_image_sizes’, function( $sizes ) { return array_filter( $sizes, function( $val ) { return ‘medium_large’ !== $val; // Filter out ‘medium_large’ } ); } ); Not sure if you’re trying to remove all the intermediate sizes, but then you … Read more

Programmatically get images by URL and save in uploads folder

There’s actually a great function that will do all three of those things for you: media_sideload_image( $url, $post_id, $description ); The first argument is the remote url of the image you want to download. The second argument is the post id of the post to which you want to attach the image. The third argument … Read more

Is it possible set a featured image with external image URL

Yes, it’s possible and pretty easy. This is the workflow I suggest: Put somewhere a UI to insert the URL of the featured image. Probably best choice is to use ‘admin_post_thumbnail_html’ filter hook Use ‘save_post’ action hook to save the URL (after security and validation routine) in a custom post meta Use ‘post_thumbnail_html’ filter hook … Read more