Articles of attachments

Images not being generated at correct size

I have my WordPress Media settings set like so. Based on these settings no generated large image should exceed the width of 540px. I embed an image in a post like so. I choose “Large” as a image size, which should have a restricted width of 540px. The end result is an image of 1024x769px. […]

Show how many images are attached to a post/page on compose page

On the front-end, I’m using a query to show all attachments attached to the current post. However, on the compose page, there’s no way for a user to see how many images are attached without opening up the media gallery. I would like to add a meta box (or something) to display the current number […]

Adding width and height to wp_get_attachment_image_src

I’m trying to add the width and height attributes to the wp_get_attachment_image_src. Why is this returning width and height:0? <?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), ‘two’ ); if ($image) : ?> <img class=”attachment-two” src=”<?php echo $image[0]; ?>” width=”<?php echo $image[1]; ?>” height=”<?php echo $image[2]; ?>” /> <?php endif; ?> Thank you!

How to get meta value in wp_attachment_metadata

I want to get wp_attachment_metadata in my own way. I want to separate the sizes (Thumbnail, Large, Medium, Small). The meta value on database looks like this: a:5:{s:5:”width”;i:660;s:6:”height”;i:320;s:4:”file”;s:39:”2013/07/debut -busana-muslim-new-yor.jpg”;s:5:”sizes”;a:2:{s:9:”thumbnail”;a:4:{s:4:”f ile”;s:39:”debut-busana-muslim-new-yor-150×150.jpg”;s:5:”width”;i:150;s: 6:”height”;i:150;s:9:”mime-type”;s:10:”image/jpeg”;}s:6:”medium”;a:4:{s: 4:”file”;s:39:”debut-busana-muslim-new-yor-300×145.jpg”;s:5:”width”;i:30 0;s:6:”height”;i:145;s:9:”mime-type”;s:10:”image/jpeg”;}}s:10:”image_met a”;a:10:{s:8:”aperture”;i:0;s:6:”credit”;s:0:””;s:6:”camera”;s:0:””;s:7: “caption”;s:0:””;s:17:”created_timestamp”;i:0;s:9:”copyright”;s:0:””;s:1 2:”focal_length”;i:0;s:3:”iso”;i:0;s:13:”shutter_speed”;i:0;s:5:”title”; s:0:””;}} Well, I am stuck. I don’t know how to separate that array. Anyone knows how to separate that […]

Show attached media image if no thumbnail image detected

I use the if ( has_post_thumbnail() ){} to check if the post have thumbnail image, but this echo get_attached_media(‘image’, $post->ID); displays the word Array I need to show the attached image

Applying class to links around self hosted images embedded to posts/pages

So I need to add a class to links around the images for lightbox purposes. But only to images from the upload directory, not to external ones. I’ve found this solution by @TommiForsström here: function add_colorbox_class_to_image_links($html, $attachment_id, $attachment) { $linkptrn = “/<a[^>]*>/”; $found = preg_match($linkptrn, $html, $a_elem); // If no link, do nothing if($found <= […]

How to access featured image?

I saw this code as how to set a featured image for a post: // required libraries for media_sideload_image require_once(ABSPATH . ‘wp-admin/includes/file.php’); require_once(ABSPATH . ‘wp-admin/includes/media.php’); require_once(ABSPATH . ‘wp-admin/includes/image.php’); // $post_id == the post you want the image to be attached to // $video_thumb_url == the vimeo video’s thumb url // $description == optional description // […]

Do attachments added to custom post types have a post parent?

On attachment pages, I have a link back to the post/page where the file was uploaded. (This is not displayed for files that were directly added to the Media Library and that’s fine.) For attachments added to posts and pages, the following code generates the link: $post = get_post( get_the_ID() ); if ( $post->post_parent ) […]

How do I delete thousands of unattached images?

I have thousands of unattached images with no files. How do I delete them all quickly? ls: cannot access wp-content/uploads/2014/09/jeep cherokee patriot-Ekza.jpg: No such file or directory

How to create a CSV on the fly and send as an attachment using wp_mail?

I’m trying to create a CSV file from a form submission and send that file automatically by email to a specific user. The email itself is sending fine, but I can’t get the attachment to go through. Is it possible to create an attachment without first saving the file to the server? function create_csv() { […]