Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

0
votes
1answer
11 views

Using delete_attachment to prevent an attachment not working

I'm having an issue where the attachment is being deleted despite me returning false function action_maybe_delete( $id ) { echo "Let's not delete Attachment id: " . $id ; // prevent the ...
0
votes
0answers
19 views

How can I delete a file off of Amazon S3 within the WordPress ecosystem [closed]

I want to access my S3 bucket, and when I remove a file, use the delete_attachment hook to call to Amazon and delete those files ( we have a service that offloads files to S3 but doesn't delete them. ...
0
votes
1answer
7 views

Remove post with attachments hook

So I have a link that removes a post. I also have some code in my functions.php wich should be hooked to the wp_delete() function. However. The function doesn't seem to work. What am I doing wrong? ...
0
votes
1answer
27 views

copy attachments to another post type and change attachment url

On my site I have to custom post types and a function that let's users import photos from post type A to post type B, copying the meta values and it copy's the image to the folder specified for post ...
0
votes
0answers
13 views

wp_delete_attachment doesn't delete image files / doesn't work

wp_delete_attachment should delete everything that is about attachment. However if I do wp_delete_attachment( (int)$delete_attachment_id, true ); The files remain on the server (even true should ...
1
vote
0answers
17 views

Is it possible to share media files between multiple WordPress sites?

We've got around ten or so WP sites on different instances of WP (each with it's own database), most of them are on the same server but not all of them. We would like to achieve a situation where an ...
0
votes
0answers
10 views

automatically move to media library

I need to move the attached images by users when using the insert from url option, and move those images automatically to the media library. Anyone know of any plugin to do this?
0
votes
1answer
30 views

Get attachment URL from attachment Link in WordPress

I have been trying to fetch the URL of image attachments ( e.g. - http:// localhost/mytheme/post-format-gallery/100_5478.jpg ) using their attachment links ( e.g. - http:// localhost/mytheme/post-...
0
votes
0answers
13 views

custom saved media attachments delete from media library but not physically from folder

I'm doing some image processing using ffmpeg which saves a new media file and then i attach this file to a post using wp_insert_attachment followed by wp_generate_attachment_metadata and ...
0
votes
1answer
23 views

Removing images deleted from uploads folder, from Media Library

How can I remove images that have been deleted from the upload folder, from the Media Library?
0
votes
1answer
14 views

Setting an image as post header (not featured image)

I am not a WordPress expert and need your support. Is there a way to create a button just like Set featured image but that button will allow us to attach an image to a post (from gallery) as a meta ...
1
vote
1answer
55 views

Adding Featured Image to Post programatically

How do I add a Featured Image programatically, given the URL/filename of the image, and Post ID associated with it?
0
votes
0answers
27 views

How can I use an image from an external source without uploading it to the media library

I am looking for a way to tweak my xml parser code to insert a url from an external source into a new post, instead of first uploading it to the website's media library and than adding the attachment. ...
0
votes
0answers
6 views

Determine From Database or Export File Whether Full Image or Not

I have a Wordpress export file. How do I tell whether an attachment is the original or not? I need to import the original and skip any versions of the original such as thumbnails, etc.
0
votes
1answer
21 views

How does WordPress treats attachments metadata in post content?

I understand that an "Attachment" object can have its own metadata in Media Library. However, it can also have it's own metadata in a post scope. How does WordPress deals with attachment metadata? ...
0
votes
1answer
31 views

Link to the parent post in attachment page

I want to show a link on the attachment page which takes one back to it's parent post. Currently in my theme I do not have that option, the links I get on the attachment page are Previous/Next links. ...
0
votes
0answers
13 views

Switch which IPTC field WordPress defaults to for the image title on upload

While looking at the core code documentation, I see wp_read_image_metadata() ( https://codex.wordpress.org/Function_Reference/wp_read_image_metadata ) decides how to populate image "titles" via this ...
1
vote
0answers
19 views

I have a site where attachments in the wp_posts table have guid values of guid, how did this happen?

I realise comparing this particular website with all the other WP sites I've built that all the others have the image url in the guid column of the wp_posts table, yet this problem site just has "guid"...
1
vote
0answers
28 views

How can I attach Facebook Open Graph data to an Attachment Page?

I have code in my page header which properly creates the Open Graph tags for pages, posts, etc. However, when I attempt to Share an attachment post from the Media Library (not the actual attachment ...
3
votes
1answer
26 views

Display Single Attachment Image file size, uploaded date, resolution, file-name etc in Sidebar

Sorry for any wrong details. I am totally new to WordPress development. I am running a photo site. On single attachment page, I want to show the details (i.e upload date, filename, size, resolution) ...
2
votes
1answer
77 views

Display one random image, but only if landscape

I want to pull one random image and use it as a background image —- but ONLY if it's a landscape image. I found this post: https://stackoverflow.com/questions/37537577/wordpress-query-by-attachment-...
0
votes
1answer
19 views

How to open an attachment based on the date picker

I am creating an E-Paper kind of functionality in WordPress where the user will have to select a date from the date picker and the corresponding attachment will open. I looked all around but didn't ...
0
votes
0answers
109 views

Send data url string as an attachment in wp_email

We have a data url string of png image file here and we can pass it via ajax to a php function via button click. Now is it possible to convert it back as image file and add as an attachment to ...
0
votes
1answer
31 views

ajax delete value from custom field array

I have on my page a multi file upload that saves post attachments within a custom field --- if (!empty($_FILES['vidPix']['tmp_name'][0])) { $i = 1; $files = $...
1
vote
1answer
36 views

Email Attachment from Form Submit

I am currently encountering a very strange problem. With the help of two existing wordpress functions (wp_handle_upload and wp_mail) and a form that uses some custom ajax functionality to process my ...
0
votes
1answer
51 views

Save attachment custom fields on front end

I have a front end post form that lets users upload multiple photos and on there I have 2 input fields to try and save custom meta data for each attachment - $vid_pix = get_post_meta($v_Id, 'vid_pix',...
0
votes
0answers
6 views

redirect attachment media pages to a new directory

I'd like to add all my attachment media pages to a new category I created called "none" /none/. Then Im going to block /none/ in my robots.txt because I hate attachment media pages. So I tried the ...
0
votes
0answers
12 views

Using 'post_parent' only works sometimes for attachments

I need to get all attachments with a specific post parent. To do this I used the following code: //this doesnt work $attachmentsids = get_posts(array("posts_per_page" => -1, "post_type" => "...
0
votes
0answers
14 views

Rename All Attached Image on Post

I have this code from a plugin that renames all featured image, how can i make this to rename all attached images on my post not only the Featured Image. Thanks!: public function wpRFP_rename_fimg($...
1
vote
0answers
129 views

Send multiple attachments with wp_mail in PHP

I'm trying to send multiple attachments with wp_mail() , after some issues of attachments names (it displayed something like phprTxfd.pdf instead of file_name.pdf), i succeeded to display the name of ...
0
votes
0answers
118 views

Using wp_insert_attachment() with TCPDF to save PDF files

I am trying to generate dynamic PDF files, and for that I am using TCPDF. At one point I like to save those PDF files as attachments in WordPress and for that I would like to use wp_insert_attachment()...
1
vote
1answer
11 views

Get all attachment by post excluding featured and content inside

I have a portfolio where for each item i have some images inside the content, a featured image and a custom filed called "portfolio images". I want to get all images by post excluding the fetured ...
3
votes
1answer
83 views

media_handle_upload for local files?

I am creating an image on the server and storing it in a tmp folder. I would like to run a php file that takes this image, stores it in the default media directory structure and attaches it to a post ...
0
votes
0answers
225 views

Fetch wordpress video attachment with post ID

So I have wasted 5 hours of my life to figure how to fetch wordpress custom post videos and been unsuccessful and here i am. Looking for expert advice. My Requirement: - Fetch all video attachments ...
0
votes
0answers
177 views

How to attach file with wp_mail(). [duplicate]

I have a custom form by which i try to send email with a file attachment but attachment not send. I don't know well how it works. When i pass $attachment variable, email not working . Email is working ...
0
votes
0answers
16 views

Customize wordpress media uploader and attachment fields

I am trying to customize the wordpress media uploader. Example: Instead of two tabs(Upload files, Media library) I want to have one tab where Upload files comes before media library. But I don't want ...
0
votes
2answers
76 views

How to disable post-thumbnail from generation?

In my theme there is a set of add_theme_support( 'post-thumbnails' ); set_post_thumbnail_size( 470, 680 ); which is actually generating one more image besides the default small,medium,medium-large,...
0
votes
1answer
8 views

Is there a function for getting the post/page that an attachment is related to?

I am working on a custom attachment.php template file for a theme and I want to make it link back to the document that the attachment is included within. Naturally an attachment may be in multiple ...
0
votes
0answers
10 views

Display audio file in audio.php

This is gonna sound stupid, but I couldn't find the answer anywhere: I need to have an attachment page for audio files (audio.php), but I have no idea how to display the media player on this page. ...
0
votes
0answers
31 views

How to redirect image files to original attachment post in wordpress?

How can I redirect the image files, so example domain.com/wp-content/uploads/75/2018/05/image-2423.png to the original post, whats attachmented to this image, or the attachment page of this image? (...
0
votes
1answer
29 views

How to get $attachment->ID in custom functions

This is what I have now within an attachment theme template... //GET THE URL OF THE ATTACHMENT $parsed = parse_url( wp_get_attachment_url( $attachment->ID ) ); $url = dirname( $parsed [ 'path' ] ) ...
0
votes
1answer
21 views

Remove all video attachment, both files and post/postmeta from database?

I am trying to make a function which deletes all the video files + the attachment post and attachments postmeta from the database. This should run when the user role is switched to "basic". And if the ...
0
votes
0answers
68 views

wp_update_attachment_metadata filter is not working

I am customizing WordPress behavior by adding filters. In my plugins.php file I have: add_filter ( 'wp_update_attachment_metadata', array ( $post_asset_uploader, 'handlePostAssetUpload' ),...
0
votes
0answers
16 views

Generate a thumbnail only for the first image & resize images if too big and delete originals

I built a plugin that for each new post, it uploads 5 pictures (from URL). The first one is the Thumbnail and the other 4 images are regular attachments. I'm using the code on the following topic and ...
0
votes
0answers
39 views

Change the attachment/mime type icons to icon font (font-awesome)

This answer (https://wordpress.stackexchange.com/a/204055/141549) shows a filter to change the icon image urls, but is there any way to go further and replace the entire html of the 'img' so that we ...
0
votes
0answers
12 views

How can I get the URL of an image in wp.media immediately after upload?

I am building a small plugin using WP Media Uploader used in frontend. The problem is I would like to get the URL of the newly uploaded file without having to 'select' the image. Any workarounds is ...
0
votes
0answers
37 views

Custom permalink for attachment

I am trying to rewrite my permalinks for attachments, which would open the attachment.php post. I found some code from this answer and have modified it to look like this: function ...
1
vote
0answers
50 views

“Scattered” gallery

I'm building a theme for a portfolio-type site. I'm looking for something like this: This site uses some kind of Foundation Grid CSS to size the thumbnails using different sizes. My question is, ...
0
votes
1answer
15 views

Unable to get all the Posts Attachments

I want to retrieve all the image attachments from a posts and render it in a gallery. Some how the number attachments which is being returned is only one even tough the posts contains multiple image ...
1
vote
0answers
27 views

Prevent Delete Attachment by URL or When Submit

This code is working, which prevent being deleted by specific title: add_action( 'delete_attachment', 'check_relations' ); function check_relations( $post_id ){ if(get_the_title( $post_id ...