An attachment is an image or other file uploaded through the post editor's upload utility. Attachments can be displayed on their own 'page' or template. For more information, see Using Image and File Attachments.

learn more… | top users | synonyms

-1
votes
1answer
45 views

How to force regenerate thumbnails in Wordpress posts?

We recently changed themes. The new theme uses different dimension thumbnails and I was a bonehead and deleted all previous thumbnail sizes. Deleting the thumbnail sizes results in many of the images ...
1
vote
0answers
36 views

Attachment page 404

After I uploaded some files into the Media Library, I clicked "View attachment page" in "Attachment Details", but I got a 404 not found error. The URL is like http://example.com/filename/ and there is ...
0
votes
1answer
30 views

Delete all attachments not used in post? [duplicate]

The site has 14,083 files, at least 3,000 are not used in publications. How do I delete all the images that are not attached to the post?
0
votes
1answer
46 views

WP media attachment location vs permalink

Yesterday I moved my sites from http://www.example.com to (secure site and removed the www). Now when I look at an attachment page I see the File URL as the old http://www ... but the page permalink ...
0
votes
2answers
77 views

Get the path of the first attached media (single.php)

I'm currently developing a wallpaper website using WordPress and I'm trying to figure it out how to retrieve the path of the first attached media in the post so I can display the path in the post ...
1
vote
0answers
38 views

wp_upload_bits Upload Specific Sizes Only

For images uploaded using this code, I want to only upload the full-size image and the thumbnail (whereas for images uploaded through site, I want all sizes). However, I can't figure out how to make ...
4
votes
3answers
683 views

List most recent image uploads, but only for specific custom post type

I can get a list of the most recent image attachments like so: $attachments = get_posts( array( 'post_type' => 'attachment', 'posts_per_page' => $number, 'post_mime_type' => ...
1
vote
2answers
3k views

How to remove images from showing in a post with the_content()?

Trying to learn more about creating my own themes and not using any plugins I wanted an ability to display all the images in a post excluding the thumbnail in my single-foobar.php file and I can do ...
0
votes
0answers
11 views

Media settings image sizes ignored in attachment display settings when uploading image

I know this question has been asked before here; Settings in 'Media > Settings' is ignored when inserting images I tried all suggestions and none of them work for me. I've set the image ...
1
vote
3answers
207 views

How to allow empty title for attachments?

When adding an image attachment to a post, the Title field is always filled automatically with the file name. For some images I change this into something more meaningful, for other images I want ...
0
votes
2answers
471 views

Unable to get wp_get_attachment_url to show

I'm trying to show a link to the full size image of an attached image. I took a code for Wordpress' Twelve Thirteen theme: <?php $metadata = wp_get_attachment_metadata(); printf( '<span ...
0
votes
0answers
12 views

Prevent non-admin to deattache media

We use Woothemes Sensei plugin as our Learning Management System. We also use Sensei Media Attachments plugin, in order to attach PDFs to our lessons CPT. Well, from time to time some PDFs are being ...
0
votes
1answer
10 views

Get posts associated with media attachment

Is there a good way to find all posts that contain a specific image? I'm working on the attachment single template, and I'd like to list the posts that contain that image.
0
votes
0answers
23 views

Redirect Attachment to parent or homepage not working on Firefox

to prevent attachment pages to be indexed in SERP, I usually use the option in Yoast SEO plugin to redirect attachment to post parent page. But it does not work when an attachment has no parent, that ...
0
votes
1answer
24 views

How to Insert images in WordPress using code

I am trying to create a plugin for auto posting. I was able to create new post and then get the attachment for the post. But images are not showing inside the post itself. but if I click on media ...
0
votes
1answer
640 views

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 ...
5
votes
1answer
58 views

Detect if is image unattached

I have problem with unattached attachments. I use image.php to show Wordpress image gallery. I always show "big image" (for current clicked image)...and under that image I show rest thumbs from that ...
1
vote
2answers
53 views

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 . ...
6
votes
2answers
236 views

Remove Dimension from wp_get_attachment_image

I am having some issue removing the width and height from my attachment images when using wp_get_attachment_image. This is what I am using to display the image <?php echo $image = ...
0
votes
1answer
72 views

Why does wp_mail become so slow when adding a local file attachment?

I have a mail template in Contact Form 7 3.5.4 where I add a standard file attachment which is already on the server (PDF of about 10MB) to an email. I receive the email including the attachment and ...
0
votes
1answer
630 views

save_post not working with attachments

I've made a Meta Box for Posts and Pages, and while testing added Attachments too. But, curiously, the hook save_post does not fire. $cpts = apply_filters( 'my_filter', array( 'post', 'page' ) ); // ...
0
votes
0answers
133 views

Set Attachment Image File URL as GUID

I have a form that uploads images and i want to update the GUID to be the attachment file url after WP generates the metadata. I tried to use wp_update_post, but seems that is not updating the guid. ...
3
votes
2answers
2k views

remove missing image attachments

Best way to programatically remove attachments that are missing images? I ask because after using a caching plugin, I have images that have been input in the database as attachments that don't ...
0
votes
1answer
167 views

Upload and attach to a post multiple image files [closed]

In a front end form I have a 'multiple' input field for uploading and attaching images to a post and a processing script (from here). I expect that will be uploaded and attached all files that I have ...
0
votes
1answer
171 views

Delete post image attachments with jQuery from the front end

In my WP 4.4 Twenty Sixteen child theme I want to delete post image attachments from a front end form created by a plugin. To achieve this I followed this answer, but the delete links doesn't delete ...
0
votes
1answer
53 views

How to get image URL from media_sideload_image?

I upload external images for media library using following way. $new_image_url = media_sideload_image($new_url, $post_ID, $title); This method return complete img src tag or 'src' for the image ...
0
votes
1answer
62 views

Redirect attachment URL

Is anyone able to Redirect the following permalink URL for me? The URL that WordPress is: http://example.com/?attachment_id=411 I would like to redirect it to new structure i do it, The following ...
0
votes
1answer
20 views

Delete custom post type metadata without deleting the post in admin area

I'm working on a plugin for a client and they need the ability to attach a couple of PDFs to a post as metadata. The client will need to occasionally update these attachments but without deleting the ...
0
votes
1answer
48 views

How To Query All Attachment Images Found In Post Galleries

I'm trying to create an image gallery which is comprised of all of the images attached to posts. The query below works well, but it ends up with all attached images rather than just the images ...
0
votes
4answers
4k views

Get the attachment URL on single.php

i've been trying to get the attachment URL on single.php, so far this code gets the DIRECT LINK to the image; <?php if ( $attachments = get_children( array( 'post_type' => 'attachment', ...
0
votes
3answers
39 views

What will happen if I delete all my attachment type posts from database?

OK maybe I'm a bit hysterical about performance, but I don't see any reason to have more than double the post entries I need in my database. I mean every image automatically creates an attachment ...
0
votes
0answers
49 views

How to update post_parent on images uploaded via Add Media button from front-end

I'm working on a plugin that will allow registered users to post content from front-end. I added WordPress default Add Media button on TinyMCE and noticed all the images uploaded via Add Media get ...
0
votes
0answers
23 views

How to replace attached media through programmatically?

I am not sure, whether the similar question exist before. I tried to get but , couldn't get the similar question. Actually I want to replace an attached media with new image. Which Means, I am ...
1
vote
2answers
792 views

Import Attachments - not attaching to post_parent

I've set up a dev site for a client, for who we're overhauling their existing site. One thing I wanted to do is import all their existing news posts, and carry over any images attached to those. I've ...
2
votes
1answer
50 views

Attachment page per category

I want to display a custom attachment page for a specific category, i.e. attachment page for category wallpapers should have a different template than category cars. Any suggestions?
1
vote
1answer
45 views

Attach previously uploaded image to post - current code has unexpected results

What code currently does: I feed post id & previously uploaded image id, code processes it all and does its magic described below. Result: unattached old image and new attached image. What I ...
0
votes
0answers
19 views

Image upload on theme option page

I've found this script for adding some theme options in wordpress. add_action( 'admin_init', 'theme_options_init' ); add_action( 'admin_menu', 'theme_options_add_page' ); function ...
0
votes
0answers
23 views

Can't Change post_name from the following code

I am attaching my custom uploads through the following code and I am trying to change the post_name during upload. But its still keeps the file name instead of my custom title. function ...
3
votes
3answers
501 views

How do I exclude all images from a wp_query?

I want to query attachments and exclude all images. I can see how to include only images, using 'post_mime_type' => 'image/*', but I couldn't find any way of achieving the opposite. Is there any ...
1
vote
2answers
34 views

How to compress image before inserting to wordpress using wp_insert_attachment function?

Is it possible that when user submit multipart form for creating a new post in wordpress, all the images are inserted using wp_insert_attachment() to media library with compression so the uploading ...
0
votes
1answer
79 views

Removing delete permanently button in uploading files media

How do I delete or remove the word Delete Permanently in uploading files? I wanted to remove this permanently so that the users won't keep deleting files which are not supposed to delete. I use ...
0
votes
0answers
58 views

Insert image caption (metadata) in shortcode in functions.php

I've created a shortcode that displays a random image given that certain parameters are filled, like img url and number of images to random through. It looks like this: function randimg_shortcode( ...
0
votes
1answer
36 views

How to test if there are no more previous or next image on attachment page?

I have a next_image_link and previous_image_link as a navigation on my image.php but I want the first and last image to echo greyed out text (disabled button) to show prev button and next button. ...
0
votes
0answers
11 views

Custom Contact Form - Attachement and receivers

I have created a custom contact form using this code: function contact_form_markup() { $form_action = get_permalink(); $author_default = $_COOKIE['comment_author_'.COOKIEHASH]; $email_default ...
0
votes
1answer
40 views

Query All Attachments and Order by Parent Publish Date

I'm working on a project where I need to query all of the image attachments and then organize them based on the date the post they were attached to was published. The query below worked well, except ...
0
votes
0answers
75 views

Upload Multiple image attachments and save their IDs in custom meta fields from Front-End

Need some help on this one. I'm trying to upload multiple image attachments via Front-End and save their IDs in custom fields. Right now only the first image gets saved as custom field ...
0
votes
0answers
13 views

Restricted Attachments/Change Attachment Upload Location

I need a way to have certain post attachments (images/pdfs/etc) be restricted to specific logged in users. What is the best way to do this? At a high level it seem like I need to do the following: ...
0
votes
1answer
53 views

wp_generate_attachment_metadata for non-images files

I created a frontend form for upload images and worked fine. The only problem is that I need generate attachment metadata for non images file. Now, metadata is only created for images files. I'm ...
1
vote
1answer
505 views

Multiple images in one attachment page

I want multiple images for one post attachment page, but there is no option for that. How can I do that?
3
votes
2answers
517 views

How to set a default meta value for custom field

I have setup a custom meta_key for attachments. Since it is a radio button with Yes/No options, and the default value is always Yes, I need that this default value is saved into the db when the ...