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
Join us in building a kind, collaborative learning community via our updated Code of Conduct.

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.

-2
votes
0answers
23 views

Wordpress wp_get_attachment_image_srcset selects the wrong image based on media size

I'm using Wordpress and want to display the right image size based on wp_get_attachment_image_srcset. The browser is changing images as I resize, but not working with the steps it should. These are ...
0
votes
0answers
11 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
17 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
22 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
24 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
76 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
14 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
28 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
29 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
18 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
26 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
13 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
46 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
52 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
36 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
220 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
49 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
14 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
71 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
8 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
18 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
27 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
19 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
44 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
32 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
9 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
28 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
48 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 ...
1
vote
1answer
32 views

Get attachments from a post

I created a snippet to get all attachment from a post, included attachments from comments. <?php $post_attachments = get_posts( array ( 'post_type' => 'attachment', 'posts_per_page' =&...
0
votes
0answers
36 views

Overriding Generated Attachment Post URL

For a plugin I am developing I need image uploads from a Custom Post Type to go to ./wp-content/uploads/clients instead of ./wp-content/uploads/{YYYY}/{MM}. I managed to solve this with the following ...
1
vote
1answer
31 views

Stopping WordPress from Auto Generating Image Files for Sizes

I have a custom post type with an image upload meta field. Every time I upload it an image with it though, I am getting extra image files for each of the predefined sizes from the theme's functions....
0
votes
0answers
44 views

File was uploaded, but it is not shown on media section of the dashboard

I managed to add an upload field to the user registration form of the website I'm building. I, also, was able to handle the upload. However, despite the file was correctly copied to the uploads ...
1
vote
1answer
49 views

How can I store a file in the database in the same way WordPress and ACF do?

I'm taking input from a Caldera Forms form which includes a user upload. This is returned as an array containing the file name: ["company_logo"]=> array(1) { [0]=> string(73) "https://...
0
votes
0answers
21 views

delete intermediate sizes previously created - Wordpress attachments

Hard to explain, so bear with me. I am working with an API, where the user sets the posts featured image on another website. I go through that API, and create/update the posts in that API. The ...
0
votes
1answer
21 views

Get Video Attachment to post

There is a plugin that let’s me upload a title, description and image with a form. If you send it, it creates and automatic post with the title, description and the image. The code for showing the ...
0
votes
0answers
26 views

Making a custom lightbox gallery, how do I retrieve the links of embedded youtube URLS's?

As the title says, I am trying to make a custom lightbox video gallery in my theme, where users can see a collection of videos, each having a thumbnail(featured-image) and a title and when you click ...
0
votes
0answers
12 views

Security Implications of Custom Specific Attachment Template File

I am using this custom attachment template (pdf.php) to force a download of PDF type attachments from my Wordpress site. Basically, it forces a download whenever a user visits an attachment page for a ...
0
votes
0answers
24 views

Unexpected issue when using attachment_fields_to_edit filter

I am developing my plugin to add a custom attachment fields. I used attachment_fields_to_edit filter (https://codex.wordpress.org/Plugin_API/Filter_Reference/attachment_fields_to_edit) to resolve my ...
0
votes
0answers
28 views

Attaching and detaching image to the post without deleting the original image in media library

I have CPT advert to which I want to attach image(s). I am able to attach images to the CPT using the image that is already in media library, however when trying to delete the image I also delete the ...
0
votes
2answers
462 views

Auto create file and send it via wp_mail()

I am getting dynamic content on page load and sending it via mail using wp_mail(). Right now all contents going in body section of email but I want it to store in .doc(MS word) file and then send that ...
1
vote
0answers
99 views

Issue to get wp_get_attachment_image with cmb2

I have a problem get the image with cmb2, I have tried in many ways without successm according to the documentation, this is fine, what can I be doing wrong? add_action( 'cmb2_admin_init', '...
0
votes
1answer
126 views

Automatically delete attachments and posts [closed]

Does anyone know of a plugin or function that automatically deletes after a certain period posts and media from Wordpress? I have a news site and have news of more than 2 years that I want to delete ...
4
votes
3answers
88 views

How to get all files inserted (but not attached) to a post

How do I retrieve the IDs of unattached media in my post? I have two posts: POST A and POST B and a PDF file called file.pdf. I've uploaded file.pdf to POST A but then also inserted it in POST B. ...