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

0
votes
1answer
26 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 ...
5
votes
1answer
64 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
54 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
253 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
82 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
0answers
168 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. ...
0
votes
1answer
220 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
63 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
197 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
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
64 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
3answers
40 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
53 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
27 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 ...
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
48 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
24 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
506 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
85 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
66 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
39 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
13 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
43 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
87 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
15 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

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
1answer
57 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 ...
0
votes
1answer
15 views

Echo list attachment size in post

i have a post width 10 attachment image in post i want querylist 10 attachment in post as: <li><a href="url-img-attachment-sizefull-img1" title=""><img ...
0
votes
0answers
70 views

Create a Gallery and update Post Parent of Attachment Images

I need to create a gallery for a custom-post and update the post_patent of every image with the new gallery ID function create_tfuse_gallery_group($post_id) { if ( get_post_type( $post_id ) == ...
0
votes
1answer
19 views

Is there a way to get attachment data?

So, I'm no big fan of how WP stores images (image data) and I was hoping there had been made some improvements in version 4.x. But alas no. When I say image data, I mean url, title, caption, alt ...
0
votes
2answers
42 views

How do I intercept and modify the functionality of wp_get_attachment_image()?

I have a site I'm building in wordpress that has ~80GB of high resolution images, and it's exceeding my managed host's storage space. My plan is to move all the images to S3, but I noticed that ...
3
votes
1answer
210 views

How do I detach images from posts?

Firstly I've seen some topics like this, but they haven't helped me. I've attached some images to a post via "Add Media" : And for showing these attached images, I used following code in ...
0
votes
1answer
22 views

Retrieve ONLY mp3s and set a variable for use in a playlist called by single.php template?

I'm trying to stuff a variable called $work_ids with the ID of any attached MP3 files for use in a custom player (based on MediaElement.js if that matters). The library contains WAV and other versions ...
0
votes
1answer
40 views

Show last 12 uploaded images on home page, but only from posts

I want to show the last 12 images that were published with articles on my front page. This is the code to get the latest 12 uploaded images, but i want to show only the ones attached to a post ...
0
votes
0answers
21 views

Is there a function like “attachment_fields_to_edit” but for “replacing” the image?

With the "attachment_fields_to_edit" function i can put custom fields to the images when i insert them in a post. The problem is, when someone clicks on "replace" he gets the "replace image" window ...
1
vote
0answers
20 views

Query to only return the 2 newest post attachments (images)?

How can you make a query that runs through all posts in a category and outputs only the 2 newest image attachments (most posts in the category have no attachments)? My current query is like this: ...
0
votes
0answers
36 views

How to ensure all image attachment page urls are using the filename and not the title?

I noticed something strange. On just a couple of posts, where the title differs from the filename, but not all, it uses the title instead of the filename. For example, take these two images: ...
0
votes
0answers
34 views

Removing options from attachment details

In the image gallery section of my Wordpress admin, when I click on an image I get something like this: My site allows multiple users to add images and I feel that most of these fields are ...
0
votes
0answers
179 views

Dynamic attachment WooCommerce Follow-Up Emails

I am using the WooCommerce Follow-Up Emails plug-in for my clients website. With this plug-in, I send a e-mail directly after the order has been finished, containing a custom template with WooCommerce ...
0
votes
2answers
14 views

Adding metaboxes to attachment pages

My script cannot save the value of the dropdown box. I could not find any helpful documentation on this topic, so I have decided to ask the StackExchange community about it. function ...
3
votes
1answer
115 views

Post being redirected to attachment post

That's strange issue I have on this one website. Similar to this problem and I am trying to get this fixed from last couple of weeks. This website have latest WordPress installed and /%postname%/ ...
0
votes
1answer
189 views

Get attachment file link

I'm building a theme that generates on the home template a link to the PDF attached to the post (it will be only PDF files). I found a solution to check if the post has a PDF attached. The goal is to ...
0
votes
2answers
79 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 ...
0
votes
0answers
518 views

How to configure Dropzone.js to work with Wordpress media attachments

I have built a site that has a public front end which shows off profile pages for cars. I have built a members only back end which allows people to create accounts, and then make a profile page for ...
0
votes
0answers
23 views

Thumbnails and active class on single attachment template

I'm building a flickr like gallery where: I have a post with Image gallery thumbnail After clicking on a thumbnail, I go to the single attachment template (image.php) and display a full image. In ...
0
votes
0answers
67 views

add_attachment in not working with wp_get_attachment_image_src

This code is not working add_action('add_attachment', 'example_file_added'); function example_file_added( $attachment_id ) { $attachments = wp_get_attachment_image_src($attachment_id,"medium"); ...
0
votes
1answer
29 views

When inserting attachments into a blog post, how can I get Wordpress to use the full filename with the extension?

I'm using WordPress as a way to keep track of several different types of data which all have different extension names -- file1.fig, file2.dat, etc. When I upload a file and insert it into a blog ...
2
votes
1answer
151 views

Can I disable this core query?

When a user creates/updates a post within the admin, it takes between 15 and 30 seconds for that operation to complete. The culprit appears to be this slow query: SELECT ID FROM wp_posts WHERE ...