Alter image output in content

Your better off adding your custom image data when you insert it into a post using media_send_to_editor, the caveat is this will not be applied to any existing images, only ones inserted after adding the function. To apply it to to existing content you will have use preg_match on the_content filter, but this can significantly … Read more

Add custom image sizes to media uploader

Invalid argument supplied for foreach means that the X in foreach X as … is not an array. You can prevent this error by type casting; add (array) before the argument in the foreach statement. This will turn your variable into an array, essentially. In your code, the change would be… foreach ( (array) $attach_meta[‘sizes’] … Read more

Adding Featured Image to Post programatically

For each image/post combination, run the following. $image_name is the filename, $post_id is the post ID. if( $image_name != ” && !has_post_thumbnail( $post_id ) ){ $base = get_stylesheet_directory(); $imgfile= $base . ‘/import/’ . $image_name; // Images are stored inside an imports folder, in the theme directory $filename = basename($imgfile); $upload_file = wp_upload_bits($filename, null, file_get_contents($imgfile)); if … Read more

How to wrap every image in a post with a div?

By default images already have unique class’s but this depends on your theme. Use firebug and hover over the images and you should see stuff like class=”aligncenter size-full wp-image-1525″. If you want to change the class or id or alter any attributes of the image you can use the get_image_tag filter. For example, add_filter(‘get_image_tag_class’,’my_custom_class’); function … Read more

Upload images using FTP and show them in media

I know it’s one year old but just in case someone else is also searching: You could upload the main files (not all 3 sizes, just the original images) via FTP to another directory on your server and then use the Add-From-Server Plugin.

The WordPress Gallery, Grabbing The Link and Images?

Attachments in a gallery are their own posts, with some special settings. To get a list of all the attachments for a given post, you basically just create a new query and specify the post parent and attachment type. $gallery_images = new WP_Query(array( ‘post_parent’ => $post->ID, ‘post_type’ => ‘attachment’, ‘post_mime_type’ => ‘image’, ‘post_status’ => ‘inherit’, … Read more