How to copy/paste web content with photos into my blog

A little tip a lot of people don’t know about. You can copy/paste an image url into the upload field and it will be auto uploaded into your blog. Right click the image you want to save and select copy image URL (chrome) In your blog click Add Image–> Select Files ( from computer)–>paste url … Read more

Hook to get image filename when it is uploaded

The handle_upload hook is called after wp_handle_upload is run, and it sends in a named array consisting of ‘file’, ‘url’ & ‘type’. You could possibly use code like this to utilise it, depending on what you need to achieve: function process_images($results) { if( $results[‘type’] === ‘image/jpeg’ ) { // or /png or /tif / /whatever … Read more

Use ‘medium’ size with catch_that_image() function

When the first image is a WordPress image attachment. in 3.6, there is an easier way. function get_first_image_medium_size_url($post_id) { if(!$images = get_attached_images($post_id)) return false; $first_image = current($images); if(!$src = wp_get_attachment_image_src($first_image->ID,’medium’)) return false; $medium_url = current($src); return $medium_url; } get_attached_images is available in 3.6. wp_get_attachment_image_src is available since 2.5.0 which will automatically get or scale the … Read more

Is there a way to get attachment data?

Don’t forget that attachments are just posts (though they are native posts and those tend to be a special case). Thus simply get_post() on attachment ID should get you typical post object for it. 🙂 Similarly all API functions that work on posts should work on attachments.

Bulk Image Uploader to create new post from each image [closed]

add_action(‘add_attachment’, ‘create_post’); function create_post( $attach_ID ) { $attachment = get_post( $attach_ID ); $my_post_data = array( ‘post_title’ => $attachment->post_title, ‘post_type’ => ‘post’, ‘post_category’ => array(‘0’), ‘post_status’ => ‘publish’ ); $post_id = wp_insert_post( $my_post_data ); // attach media to post wp_update_post( array( ‘ID’ => $attach_ID, ‘post_parent’ => $post_id, ) ); set_post_thumbnail( $post_id, $attach_ID ); return $attach_ID; }