How to get the cropped image from media library?

Get the attachment ID for the image, then get the post meta field _wp_attachment_metadata for it. This is a serialized array. The field sizes in that array contains all available image sizes. Pseudo-code: $sizes = array(); $attachment_url=”http://examle.com/wp-content-uploads/foo.png”; $attachment_dir = dirname( $attachment_url ); $attachment_id = get_attachment_id( $attachment_url ); $attachment_meta = get_post_meta( $attachment_id, ‘_wp_attachment_metadata’, TRUE ); $sizes[] … Read more

How to add “alt” attribute for image during upload at WP front-end?

The alt text is stored in the postmeta database table by WordPress, therefore we have to update the postmeta of the given attachment. The reference is done via the unique attachment ID, and the meta_key we are targeting is the _wp_attachment_image_alt. So, to set the alt text, we can do the following: update_post_meta($attach_id, ‘_wp_attachment_image_alt’, ‘Your … Read more

Inserting Media to WordPress Posts

If you use “Insert by URL” the image is loaded from whatever URL your provide. It is not uploaded to your server at all, nor is any information added to the postmeta table as far as I can tell. It seems to be equivalent to simple hand-writing the HTML into the post body. You can … Read more

Random home page background images with caption text

First of all I don’t think that create a custom post type only for backgrounds is a right choose: backgrond are images and images already have their post type: attachment. If you have Worpress 3.5+ you can register a custom taxonomy for attachments, call it, e.g. ‘image_scope’ : register_taxonomy(‘image_scope’, ‘attachment’, $args ); for the $args … Read more

How to create a title images for different posts?

You can simply use the featured image. Just output it where you want it to appear <?php the_post_thumbnail( $size, $attr ); ?> Use accordingly a class or a ID to style it with CSS. Take a look there: https://codex.wordpress.org/Post_Thumbnails to abilitate the featured image in your theme.